: What is the proper format for an htaccess redirect relating to https and subdomains I'm not sure if my syntax is correct here. I'm specifically looking to do this: Redirect all traffic to
I'm not sure if my syntax is correct here. I'm specifically looking to do this:
Redirect all traffic to the root domain (mydomain.com) to a www version (www.mydomain.com).
Redirect all http traffic to https on specific subdomains (or root domain to https:/www)
So if someone goes to the root domain (any page) they will go to the www version of that page.
If they go to two specific subdomains (www and clients) using http, they'll be redirected to the https version (either www. or clients. respectively).
If they go to any subdomain other than www or clients, then do not force https.
Here's what I came up with:
# FORCE ROOT TO WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ www.domain.com/ [R=301,L]
# END FORCE ROOT TO WWW
# FORCE SSL
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www|clients). [NC]
RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} [R,L]
# END FORCE SSL
This doesn't seem optimal. Is there a better way?
Also, this is a WordPress site and there are other rules in htaccess. Should this go at the very top of the htaccess file.
Thanks much.
More posts by @Yeniel560
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.