[英]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. 我有3个LIVE域,它们指向同一个文档根,CMS会使用其自己的内容处理每个域。
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. 现在,我需要使用WWW将所有3个域重定向到HTTPS,并可以选择将来更改每个域的文档根目录。
Example what needs to happen: 示例需要发生的情况:
http://domain1.com => https://www.domain1.com http://domain1.com => https://www.domain1.com
http://www.domain1.com => https://www.domain1.com http://www.domain1.com => https://www.domain1.com
Same must also happen for domain2.com and domain3.com domain2.com和domain3.com也必须相同
Document root for all three domain is /cms-1.1/ 这三个域的文档根目录均为/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/ 将来,domain1.com可能会更改为新文档根目录/cms-2.1/,但对于其他域,文档根目录将保持不变/cms-1.1/
Can I write one rule or multiple rules... for each domain separately or combined?? 我可以为每个域单独编写一个规则还是为多个规则组合?
So far I came up to here: 到目前为止,我来到这里:
for document root: (for 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]
for non-www to www: (for each domain) 对于非www到www :(针对每个域)
RewriteCond %{HTTP_HOST} ^domain1\\.com$ [NC] RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]
for HTTPS: (for each domain) 对于HTTPS :(对于每个域)
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://www.domain1.com/$1 [L,R=301]
But will this work ??? 但这会工作吗??? Since all three domains are live, I need not to have any downtime...
由于这三个域都处于活动状态,因此我无需停机。
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.