Mod_rewrite for http to https

New to mod_rewrite? This is a good place to start.

Mod_rewrite for http to https

Postby alinux » Mon Jul 26, 2010 6:48 am

Hi All
I have a website with three hostnames x y and z. x is the main url and I have a valid SSL certificate for it. Basically, I have no problem if a page is accessed through http, however if an https page is requested when a users registers or when a user logs in or over a few https links I want the url to be redirected to from y and z to https://x.

Example

https://y.com/test.php should go to https://x.com/test.php
https://z.com/test.php should go to https://x.com/test.php

Where test.php could be any URL.

In short, any https page requested if it is not going for hostname x it should be redirected to hostname x. Is it rewrite or redirect I need, or maybe I need both.

Any help please ?

Thanks
alinux
 
Posts: 8
Joined: Tue Jun 16, 2009 5:15 am

Re: Mod_rewrite for http to https

Postby wrathican » Wed Jul 28, 2010 2:17 am

Hi,

if you have set up Y & Z to be aliases of X, then all you need is the following:
Code: Select all
RewriteCond %{SERVER_NAME} !^x.com
RewriteRule (.*) http://www.x.com/$1 [R=301,L]


That should work.
Good luck :P
wrathican
 
Posts: 5
Joined: Tue Nov 18, 2008 1:42 pm

Re: Mod_rewrite for http to https

Postby alinux » Wed Jul 28, 2010 3:33 am

Hi
Thanks for the input will try it out later tonight, but I was wondering this will not create any SSL warnings as the URLs are overwritten ..right ?
Regards
alinux
 
Posts: 8
Joined: Tue Jun 16, 2009 5:15 am

Re: Mod_rewrite for http to https

Postby wrathican » Wed Jul 28, 2010 4:54 am

It shouldn't do. it's actually redirecting to the url instead of rewriting it.
wrathican
 
Posts: 5
Joined: Tue Nov 18, 2008 1:42 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 10 guests

cron