Forum Moderators: phranque
Because I have a secure ceckout on my site, I have put some code to redirect anything in the /checkout folder to [domain.com...] (currently using a php redirect). However people then tend to browse around my site using https:// which can cause some issues (I cant serve ads on these pages!)
I would be keen to find a nice htaccess rule, which would do the following:
If user enters any page within: /checkout then redirect to https page
if user enteres any page outside of /checkout then redirec to http page
How could I do this?
Thanks!
in /.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ [test.domain.com...] [R,L]
in /checkout/.htaccess
RewriteEngine on
RewriteCond %{SERVER_PORT}!^443$
RewriteRule ^(.*)$ [test.domain.com...] [R=301,L]
This works for 99% of cases, except when you load:
[test.domain.com...] (with no trailing slash or filename)
which then goes to:
[test.domain.com...]
Any ideas?
In /.htaccess
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteCond $1 !^checkout
RewriteRule (.*) http://test.domain.com/$1 [R,L]
the only problem is, the images css and js files are rewritten back to http:// because they are not in the checkout folder!
Can we get a slight amend so that it only redirects actual pages rather than the images, etc?
would need to deal with php pages (and obviously domain.com/ where pagename is not shown..,)
Ben
Overwrite? No. The top-level rewrites will be invoked, followed by the lower-level rewrites, but both will occur. And since an external redirect is involved, that's not good.
Ben,
You should be able to add an exclusion to the /checkout/.htaccess file, in much the same way as I showed for the /.htaccess exclusion.
I'm not clear on all the exclusions you might need, but the pattern for css and js files would be something like
!\.(css¦js)$
Note: No start anchor, because we're only looking at the .js or .css suffix, and you must replace the broken pipe "¦" character shown with a solid pipe character from your keyboard; Posting on this forum modifies the pipe characters.
Jim
Jim