Forum Moderators: phranque
I'm a novice to mod_rewrite and Webmasterworld.com. I've been trying to use mod_rewrite to force a specific link from http to https.
FROM
http://www.example.com/path/to/login/index.php?Object=Page&Name=Home.htm&login=true
TO
[example.com...]
Here is something I tried but some how it does not work...anything I'm missing here?
RewriteCond %{QUERY_STRING} ^Object=Page
RewriteCond %{QUERY_STRING} Name=Home\.htm
RewriteCond %{QUERY_STRING} login=true
RewriteRule ^/path/to/login/index\.php$ https://%{SERVER_NAME}/path/to/login/index\.php?Object=Page&Name=Home.htm&login=true [NC,L]
-zeon
RewriteCond %{QUERY_STRING} ^Object=Page&Name=Home\.htm&login=true
RewriteRule ^/path/to/login/index\.php$ https://%{SERVER_NAME}/path/to/login/index\.php?Object=Page&Name=Home.htm&login=true [NC,R=301,L]
If none of the above is helpful, please define "it doesn't work" and tell us how you tested, what results you got, and how those results differed from your expectations.
One more thing: If your https files are located in the same directory-path as this code, then you'll need an exclusion in the rule to prevent looping:
RewriteCond %{SERVER_PORT} !^443$
> About the 301 redirect and "RewriteCond %{SERVER_PORT}!^443$", are they really necessary since I have not include those two things and it is working fine...
If the conditions for my statement above are met, then check the redirect response with a server headers checker to be sure you aren't redirecting https to https until the browser or server gives up. I recommend the "Live HTTP Headers" add-on for Firefox/Mozilla-based browsers.
Jim