htaccess – Force HTTPS Traffic Except One Domain

.htaccessapache-2.4

I am trying to force all traffic to HTTPS except one domain, however, I cannot get this to work.

RewriteEngine On

# Disable directory browsing
Options All -Indexes

# Exclude the following site
#RewriteCond %{HTTP_HOST} !excluded\.example.com [NC]

# For the rest of sites force HTTPS traffic. 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Result > All websites redirect to HTTPS, including excluded.example.com which is not what I need. I would like to exclude that domain from HTTPS

Appreciate if someone spot what I am doing wrong

Many thanks

Best Answer

RewriteEngine On

# Disable directory browsing
Options All -Indexes

# Exclude the following site
RewriteCond %{HTTP_HOST} !^excluded\.example\.com$ [NC]

# For the rest of sites force HTTPS traffic. 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Uncommented your RewriteCond and added an escape character. The ^ marks the start of the string and $ marks the end. Please let me know if this doesn't work out!

Related Topic