Reputation: 11
I have a new website and am trying to make it https. I am embedding a forum on one page. The forum does not come in https ! Thus I need that one page to be served over HTTP, and not HTTPS. I am using the standard htaccess code to force all pages to go to HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I read up on syntax a bit, but it is very complex. I think I want to do something with the RewriteCond , because from what I read that will create an exception to the rule right below it.
My forum is on http://www.xxxx.xxx/forum.html
How to write the rule to make an exception for that page?
Upvotes: 1
Views: 2056
Reputation: 4917
You can use the following rules in your .htaccess
file. What this does is first check if HTTPs is not on, if not, then it will forward everything to HTTPs except for the directory forum
. The second rule checks if HTTPs is on, if so then it will redirect forum
back to HTTP.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} !^\/(forum)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} ^\/(forum)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
Make sure you clear your cache before testing this. If you have problems with the above rule, then you can also try the following:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/forum
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/forum
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Upvotes: 1