How do I force SSL for a particular domain currently I have
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is working, however I have several add on domains on my hosting and when I try to access the other add-on domains, the add-on domains are also forced to use SSL.
I tried this:
RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.exampledomain\.org$
RewriteRule ^/?$ "https\:\/\/www\.examplemydomain\.org\/" [R=301,L]
But it is giving me an infinite loop.
This should work:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} exampledomain\.org$ [NC]
RewriteRule ^ https://www.examplemydomain.org%{REQUEST_URI} [R=301,L,NE]
It looks like you're doing 2 different things here. You're adding a www
when one is missing, and you're forcing SSL when it isn't used. So there's 2 different conditions and either one being true should force a redirect. That means you want to use the [OR]
flag, but the way you were using it breaks if the request is already SSL. Try:
RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.examplemydomain.org/$1 [R=301,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With