Forum Moderators: phranque

Message Too Old, No Replies

Url is not returning into https

rewriting, https redirection

         

zaira_86

11:00 pm on May 5, 2010 (gmt 0)

10+ Year Member



Hi, what is wrong with my htaccess code below. I want my user/fast-login.html and password-recovery.html to be open in https. When i entered the link https://www.mysite.com/user/fast-login.html, it automatically changes the link into http. Same thing happen with my password recovery page.

Any idea, on what else do i need to add in my script below to make the https page work?


RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(user/fast-login.html|password-recovery.html)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|jpe|ico|css|js)$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(user/fast-login.html|password-recovery.html)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|jpe|ico|css|js)$
RewriteRule ^user/fast-login.html$ checkoutlogin.php [nc]
RewriteRule ^password-recovery.html$ forgotpass.php [nc]

[edited by: jdMorgan at 2:50 am (utc) on May 6, 2010]
[edit reason] de-linked URL in code [/edit]

g1smd

11:51 pm on May 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



..

[edited by: g1smd at 12:00 am (utc) on May 6, 2010]

g1smd

11:55 pm on May 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your code says:

1. If port is not 443, redirect login and password to HTTPS.
2. If port is 443, and it is not a request for CSS, image, JS, etc, then redirect login and password to HTTP.
3. Rewrite some URL requests to real filenames.

Some corrections.

Add the [L] flag to both rewrites (rewrites, not redirects).

Remove the [nc] flag from both rewrites as leaving it in creates Duplicate Content issues.

Add a ! NOT to the pattern in the second rule (of four), so that it redirects to HTTP anything that is NOT password or login .

Your rewrites (rewrites, not redirects) are for specific URLs ending in .html and so the RewriteCond before the 3rd rule is redundant.

Add some # comments to your code to explain each ruleset.

zaira_86

2:37 am on May 6, 2010 (gmt 0)

10+ Year Member



Sorry the second rule has really ! in my file. I just forgot to put it in there.

In my file it it like this
RewriteRule !^(user/fast-login.html|password-recovery.html)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

[edited by: jdMorgan at 2:53 am (utc) on May 6, 2010]
[edit reason] Corrected linked URL [/edit]

jdMorgan

3:03 am on May 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With the negated image-file pattern and the other corrections that g1smd noted above, and proper escaping of literal periods in regular expressions (e.g. login.html should be login\.html in your patterns), there is apparently nothing left that is 'wrong' with this code.

Be sure it is located where it will be executed for both http and https requests -- not always a given.

Be sure you've got the required setup and enabling directives for mod_rewrite in the file (test with a simple unconditional redirect of a fake URL-path request to google.com, for example), and be sure that there are no other RewriteRules or mod_alias directives such as Redirect, RedirectMatch, etc. that would preempt or countermand these rules.

Jim