Php htaccess重写语言get变量ans子目录

Php htaccess重写语言get变量ans子目录,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我找到了这段代码,它适用于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 prese

我找到了这段代码,它适用于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 这不管用。。。语言是英语

我的意思是它不适用于子文件夹…

您可以使用:

#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]

你试过我的答案了吗。。。它适用于子文件夹