my subdomain.example.com
redirecting to www.subdomain.example.com
.
Htaccess code :
# ensure www.
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
### END WWW & HTTPS
I am looking for
example.com
towww.example.com
anything.example.com
toanything.example.com
How can i fix this?
Update : i am using one htaccess file for both subdomain and root domain and i cannot use separate htaccess file for for different domain for a reason.
Note : please do not mark this question duplicate. i have already searched other part of stackoverflow and do not find a working solution.
3
Answers
For future reference :
You need restrict your rewrite condition to match only top level domain:
Make sure to clear your browser cache before testing.
Solution : https://stackoverflow.com/a/35285128/4643961
Alternative :