Force HTTPS over HTACCESS with subdomain exclusion

I am looking to force HTTPS on my site other than the subdomain that I use for the forum. I have an SSL certificate installed in the root domain, but not this forum subdomain. ( http://forum.domain.com )

Here is the code for forced HTTPS:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

However, it also forces HTTPS on subdomains, making the forum unavailable.

How to create an exclusion rule for this subdomain?

+4
source share
1 answer

To exclude a subdomain, you can use a negative RewriteCond

RewriteCond %{HTTP_HOST} !^sub\.domain\.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
+2
source

All Articles