问题描述
我有一个多域站点,
这表示根据域显示的内容版本,
Which means depending on the domain a version of content is displayed,
所以现在我拥有的域名是 chiname.com
和 greatwall.com
当用户登陆时 chiname.com
被重定向到 https://www.greatwall.com
,除了两个文件夹 /着陆
和 / marketing
保留在 chiname.com
上,但希望成为在 chiname.com
的 https
版本上。
So for now I have domains chiname.com
and greatwall.com
When a user lands on chiname.com
gets redirected to https://www.greatwall.com
except for two folder /landing
and /marketing
which stays on chiname.com
but wanted it to be on the https
version of chiname.com
.
我尝试添加rewriteRule,但对我不起作用
I tried adding a rewriteRule, but doesn't work for me
RewriteEngine On
RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(landing/.*)$ https://www.chiname.com/$1 [R=301,L]
RewriteRule ^(marketing/.*)$ https://www.chiname.com/$1 [R=301,L]
RewriteRule ^(.*)$ https://www.greatwall.com/$1 [R=301,L]
推荐答案
您可以使用以下2条重定向规则:
You may use these 2 redirect rules:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?chiname\.com$ [NC]
RewriteRule ^(landing|marketing) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC,NE]
RewriteCond %{HTTP_HOST} ^(?:www\.)?chiname\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing) [NC]
RewriteRule ^ https://www.greatwall.com%{REQUEST_URI} [R=301,L,NC,NE]
请确保使用新的浏览器进行测试。
Make sure to use a new browser for testing.
这篇关于htaccess。将排除的子文件夹重定向到域的https版本,其他所有内容都重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!