Question

I would want to force HTTPS for entire website except:

  1. Subdomains
  2. One Directory

For, one directory named efr I have done something as:

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

And now condition for sub-domain is remaining. I want to stop HTTPS for: sub-domain.domain.com and only domain.com should be HTTPS.

Please let me know how can I achieve this.

Thanks

Was it helpful?

Solution

You can add another condition to make sure this rule is applied for main domain only:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule !^efr https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top