我尝试将用户从我的root重定向到默认语言路径(如果没有设置)。这是我的htaccess文件
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
php_flag magic_quotes_gpc off
# with language
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/(create) create.php?lang=$1 [L]
RewriteRule ^([a-z]{2})/(recents) index.php?lang=$1&sort=recents [L]
# original, without language
# what rules here?
如果没有设置我想要重定向到的语言:
我该怎么做?
谢谢!
答案 0 :(得分:0)
您可以使用新规则来处理此问题:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE]
# add /en/ to URIs if missing
RewriteCond %{THE_REQUEST} !/[a-z]{2}/ [NC]
RewriteRule ^ en%{REQUEST_URI}/ [L,R=302,NC,NE]
php_flag magic_quotes_gpc off
# with language
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([a-z]{2})/(create) create.php?lang=$1 [L]
RewriteRule ^([a-z]{2})/(recents) index.php?lang=$1&sort=recents [L]