简体   繁体   English

htaccess 重写语言获取变量 ans 子目录

[英]htaccess rewrite for language get variable ans sub-directory

I found this code and it's working for www.mysite.com/fr/ or www.mysite.com/fr/login.php : the language is FR.我找到了这段代码,它适用于 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]

But for www.mysite.com/fr/directorie/blabla This doesn't work... The language is EN但是对于 www.mysite.com/fr/directory/blabla 这不起作用...语言是 EN

I mean it doesn't work for sub-subfolder....我的意思是它不适用于子文件夹....

You can use:您可以使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM