【发布时间】:2014-02-05 16:25:23
【问题描述】:
我对使用 mod_rewrite 很陌生,我一直在研究各种问题和文档文件,但没有找到解决方案。
人们可以使用 2 个主机之一访问我的网站:
www.example.com
fr.example.com
子域表示用户的语言。 如果使用 www,则语言应假定为英语。
我要做的是检测子域并将其值作为参数传递给原始请求。
这是我尝试过的:
RewriteEngine On
# match the subdomain
RewriteCond %{HTTP_HOST} ^fr.example.com$ [NC]
# Make sure I don't already have a "lang" in the query string
RewriteCond %{QUERY_STRING} !lang= [NC]
RewriteRule (.*) $1?lang=fr [QSA]
# match the subdomain
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
# Make sure I don't already have a "lang" in the query string
RewriteCond %{QUERY_STRING} !lang= [NC]
RewriteRule (.*) $1?lang=en [QSA]
我正在通过以下方式进行测试: http://fr.example.com/index.php?a=1 在 index.php 中,我正在转储请求参数的内容,但我不断收到:
array ( 'a' => '1', )
我期待看到:
array ( 'a' => '1', 'lang' => 'fr)
我正在使用http://htaccess.madewithlove.be/ 来调试我的规则,但我无法让自己解决这个问题。
我做错了什么?
提前致谢。
【问题讨论】:
标签: .htaccess mod-rewrite subdomain