我有2个域名,foo.com(主域名)和bar.com(插件域名)托管在同一个VPS上。
文件夹:
public-html/ (default folder for foo.com)
├── foo/ (desired folder for foo.com)
├── bar/ (default folder for bar.com)
我想强制https和www用于两个域,并执行隐形重定向foo.com到子文件夹public_html / foo
我在这里
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com [NC]
RewriteCond %{HTTP_HOST} !^bar.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.foo.com%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^((?!foo/).*)$ /foo/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.bar.com%{REQUEST_URI} [NE,R=301,L]
如果我删除以下规则,bar.com就可以了,而且foo.com不再工作了:
RewriteRule ^((?!foo/).*)$ /foo/$1 [L]
如何排除bar.com与此规则冲突?
答案 0 :(得分:0)
这很好用:
RewriteCond %{HTTP_HOST} ^(www\.)?bar.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.bar.com%{REQUEST_URI} [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?foo.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.foo.fr%{REQUEST_URI} [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com$
RewriteRule !^foo/ /foo%{REQUEST_URI} [L]