Reputation: 13
By default i need the site to redirect everything to HTTPS, except ONLY when a cookie is set to "admin". When the cookie is set to "admin" i need the whole site to be http, not just some pages. So far i have read a lot of entries here and there but non actually worked. Here is what i have on htaccess:
RewriteCond %{HTTP_COOKIE} (admin)
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://www.domain.org/$1 [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.org/$1 [R,L]
also tried
RewriteCond %{HTTP_COOKIE} cookie-name=admin
RewriteCond %{HTTPS} !=off
RewriteRule ^(.*)$ http://www.domain.org/$1 [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_COOKIE} !cookie-name=admin
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.org/$1 [R,L]
It still redirects me to https even when the cookie is already set. is there a way to this? thanks!
Upvotes: 0
Views: 320
Reputation: 143906
Try:
RewriteCond %{HTTP_COOKIE} !admin
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.org/$1 [R,L]
RewriteCond %{HTTP_COOKIE} admin
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://www.domain.org/$1 [R,L]
Upvotes: 1