主要问题是指令的顺序不对。你应该是
到
www.example.com
之前
重写
到
web/<whatever>
.
RewriteEngine on
# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Internally rewrite to "web" subdirectory.
RewriteRule (.*) web/$1 [L]
我想你还有一个
.htaccess
/web
子目录,否则最后一个指令将导致重写循环。
在那之后加上
/en
使其看起来像
www.example.com/en
之前
web
子目录。我想你可能会要求
www.example.com/<page>
www.example.com/en/<page>
?
RewriteEngine on
# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=302,L]
# Redirect to "/en" if not already present at the start of the URL
RewriteCond %{REQUEST_URI} !^/en/
RewriteRule (.*) http://%{HTTP_HOST}/en/$1 [R=302,L]
# Internally rewrite to "web" subdirectory.
RewriteRule (.*) web/$1 [L]
这个
RewriteCond
指令检查URL路径是否(
!
/en/
在重定向之前。