dmagnif
dmagnif

Reputation: 3

htaccess multiple domains redirect to https://www and to specific document root

I have 3 LIVE domains that point to the same document root where CMS handles each domain with it's own content.

I now need to redirect all 3 domains to HTTPS with WWW and have the the option to change each domains document root in the future.

Example what needs to happen:

http://domain1.com => https://www.domain1.com

http://www.domain1.com => https://www.domain1.com

Same must also happen for domain2.com and domain3.com

Document root for all three domain is /cms-1.1/

In the future there might be a change for domain1.com to a new document root /cms-2.1/ but for the rest of domains the document root will stay the same /cms-1.1/

Can I write one rule or multiple rules... for each domain separately or combined??

So far I came up to here:

But will this work ??? Since all three domains are live, I need not to have any downtime...

Upvotes: 0

Views: 615

Answers (1)

SayJeyHi
SayJeyHi

Reputation: 1841

you can use this generic code (not tested)

# https mechanism
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#none www to www.
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) https://www.%1%{REQUEST_URI} [R=301,NE,L]

#Document root each domain
RewriteCond %{HTTP_HOST} ^domain1.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain1.com$
RewriteCond %{REQUEST_URI} !^/cms-1.1/*$
RewriteRule ^(.*)$ /cms-1.1/$1 [L]

Upvotes: 2

Related Questions