2015-09-04 46 views
-2

我发现这个代码,它的工作原理是www.mysite.com/fr/或www.mysite.com/fr/login.php:语言是FR。htaccess重写语言获取变量和子目录

#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

我的意思是它不为子子工作.. ..

+0

你试过我的答案......与子工作 – Croises

回答

0

您可以使用:

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