我找到了这段代码,它可以为www.mysite.com/fr/或www.mysite.com/fr/login.php工作:语言是FR。
#Check for files that do not contain the language string
RewriteCond %{REQUEST_URI} !^/[a-z]{2}/.*
RewriteRule ^(.*)$ $1?lang=en [QSA,L]
#Capture the language string and present it as the variable
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/(.*)
RewriteRule ^.* %2?lang=%1 [QSA,L]
但是对于www.mysite.com/fr/directorie/blabla这行不通……语言为EN
我的意思是它对子文件夹....不起作用
您可以使用:
#Check for files that do not contain the language string
RewriteCond %{REQUEST_URI} !^/[a-z]{2}/
RewriteCond %{QUERY_STRING} !lang=
RewriteRule ^(.*)$ $1?lang=en [QSA,L]
#Capture the language string and present it as the variable
RewriteRule ^([a-z]{2})/(.*) $2?lang=$1 [QSA,L]