Forum Moderators: phranque
After browsing the forums i end up writing this code:
# Switch to https
RewriteCond %{httpS} off
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^cart.php?$ [domain.com...] [R=301,L]
# Switch back to http if https request
RewriteCond %{httpS} on
RewriteCond %{REQUEST_URI} !^cart.php?$
RewriteRule (.*) [domain.com...] [R=301,L]
The main idea is to redirect to https when a visitor goes to cart.php and redirect back to http when leaves the page.
Any ideas why the code isn't working?
Thanks.
There were also several other minor problems any of which may have caused the failure.
I'm also assuming that this code goes into your "home page" direcotry .htaccess file, and that you already have other rules in this .htaccess file that work properly, and therefore have already included the directives required to set-up and enabled mod_rewrite.
# Redirect http [b]requests for cart.php (only)[/b] to https
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^cart\.php$ https://www.example.com/cart.php [R=301,L]
#
# Redirect back to http [b]if any URL other than cart.php[/b] is requested using https
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^cart\.php$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I bolded the comments regarding this issue in the code above.
Jim