Reputation: 280
I want to force HTTPS for one of my website. Unfortunately I have other websites on my server and I don't want to redirect them to https. I tried to add a rewrite condition but it's not working. Do you know why? My goal is to avoid the https redirection for botletter.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !http://botletter.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} !http://www.botletter.com [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Thank you.
Upvotes: 0
Views: 27
Reputation: 18671
You can use:
RewriteEngine on
# To https www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# To https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# botletter to www.botletter
RewriteCond %{HTTP_HOST} ^(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
Depending on your configuration, you may need to use:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
instead of RewriteCond %{HTTPS} off
Upvotes: 1