Reputation: 25
I have a problem, I tried the all options.
I want redirect all website http to https except one directory, this directory is intranet :
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} ^\/(intranet)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^\/(intranet)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
but now the all website show http and it doesn 't redirect to the https .
Can you help me?
Thanks
Upvotes: 2
Views: 1131
Reputation: 41219
Your rule is redirecting all requests except /intranet back to http because of the negitive Rewritecondition, remove the ! char from your 2nd rule. Try :
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^/(intranet)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} ^/(intranet)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
Alternativly you could try this :
RewriteEngine on
RewriteCond %{REQUEST_SCHEME} =http
RewriteCond %{REQUEST_URI} !^/(intranet)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{REQUEST_SCHEME} =https
RewriteCond %{REQUEST_URI} ^/(intranet)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
Upvotes: 2
Reputation: 7476
Use the rule only one time like this,
RewriteCond %{REQUEST_URI} !^intranet
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
Upvotes: 0