给定此目录结构:
.
├── assets
│ └── img/
│ └── foo.png
├── en
│ └── index.php
└── fr
└── index.php
有两个域:
english.com
french.com
我的目标是
english.com => english.com/en
french.com => french.com/fr
english.com/fr => french.com/fr
french.com/en => english.com/en
没有重定向:
english.com/assets/img/foo.png
french.com/assets/img/foo.png
当前的解决方案无法正确实现上述目标
<IfModule mod_rewrite.c>
RewriteEngine On
# no www, https only
RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTP_HOST} ^www\.%{HTTP_HOST}$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(en) - [L]
RewriteRule ^(fr) - [L]
RewriteRule ^(assets) - [L]
redirectMatch 301 ^/en$ https://english.com/en
redirectMatch 301 ^/fr$ https://french.com/fr
RewriteCond %{HTTP_HOST}: englisch.com$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/en/$1 [R=301,L]
RewriteCond %{HTTP_HOST} french.com$ [NC]
RewriteRule ^(.*)$ https://french.com/fr/$1 [R=301,L]
</IfModule>
1条答案
按热度按时间dxxyhpgq1#
有这样的话:
验证它工作正常后,将
R=302
替换为R=301
。测试mod_rewrite
规则时,避免使用R=301
(永久重定向)。