【问题标题】:htaccess rewrite for language get variable ans sub-directoryhtaccess 重写语言获取变量 ans 子目录
【发布时间】:2015-09-04 21:56:11
【问题描述】:

我找到了这段代码,它适用于 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/directory/blabla 这不起作用...语言是EN

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

【问题讨论】:

  • 您尝试过我的答案吗...适用于子文件夹

标签: php .htaccess mod-rewrite


【解决方案1】:

你可以使用:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 2012-05-06
    • 1970-01-01
    相关资源
    最近更新 更多