Mobile app version of vmapp.org
Login or Join
Yeniel560

: 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

@Yeniel560

Posted in: #Htaccess

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.

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel560

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme