Forum Moderators: phranque
# Now redirect HTTP pages we want protected to SSL...
RewriteCond %{HTTPS} off
RewriteRule ^(admin/|user/|system/) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,R=301,L]
# ... and return any others to HTTP
RewriteCond %{HTTPS} on
RewriteRule ^!(admin/|user/|system/) http://%{HTTP_HOST}%{REQUEST_URI} [QSA,R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^!(admin/|user/|system/) http://%{HTTP_HOST}%{REQUEST_URI} [QSA,R=301,L]
RewriteCond %{SERVER_PORT} !=80
RewriteCond %{REQUEST_URI} !^/(admin|user|system)/
RewriteRule (.*) http://www.example.com/$1 [R=301,L] what are you doing about a general hostname canonicalization redirect ruleset? what you're saying is that negation within a RewriteRule match just doesn't work?
RewriteRule ^!(admin|user|system)/
doesn't mean "a request for any pages outside these directories"; it means "a request for any content at all that doesn't match this pattern". If, on your site, all https content is in these directories, and all non-https content is elsewhere, it might work ... except that your RewriteRule presumably involves a capture. It is not possible to capture a negative. Yep, earlier rules enforce canonical redirectsWhy earlier? Domain name canonicalization is generally your very last external redirect. Sometimes it can be combined with an http/https redirect, but only if your whole site uses the same protocol.
I'd almost given up on anyone answering
I use %{HTTP_HOST} just to save typing - the same basic .htaccess file is copied when creating a new vhost so that saves editing.
Get rid of those {REQUEST_URI} and {HTTP_HOST} elements in the target.
%{HTTP_HOST} is whatever was requested which isn't necessarily the canonical hostname.
I do my canonicalisation (is that a word?!) early on so that later I can assume HTTP_HOST on anything that gets through is what I expect
Or am I missing something important there?
http://%{HTTP_HOST}/
>>
http://www.example.com/
(a form that would only occur in a RewriteRule target) so you don't accidentally change any RewriteConds at the same time.