I have a RewriteRule
that redirects my main domain to https://www.sta-games.com
which works fine, but when I try to access my subdomain http://files.sta-games.com
, it redirects to my main domain.
Heres my redirect rules
#HTTPS Redirection
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Can anyone see the problem?
You need to adjust your rules so that it looks for the whole domain instead of just part of it. Right now you are only looking for the absence of
www
. So that is why your subdomain redirects.First you need to combine your rules because it seems you want to redirect if https is not on and there is no
www
, so make that one rule. Then use your actual domain name in the rule. Replace example.com with your domain. This should fix your issue.Have an additional skip condition for all domains except the main domain:
Test this after clearing your browser cache.