nico_lrx
nico_lrx

Reputation: 280

.htaccess rewrite to force HTTPS, how to avoid some domain names?

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

Answers (1)

Croises
Croises

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

Related Questions