将index.php?lang = 1重写为index-en.html

时间:2014-03-12 22:53:36

标签: .htaccess rewrite

我的网址是每个家庭语言的index.php?lang = 1,index.php?lang = 2等 我想将其重写为index-en.html,index-de.html等

我错过了什么,它不起作用。 第二个其他规则搞砸了,不知道。 这是我的代码:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^index.php?lang=1$ index-en.php [QSA, L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^[^/\.]+(\.html)?$  index.php?url=$0 [QSA,L]

</IfModule>

有什么想法吗? 感谢

1 个答案:

答案 0 :(得分:1)

您无法与RewriteRule中的查询字符串匹配,您需要在条件中与%{QUERY_STRING}变量匹配。所以而不是:

RewriteRule ^index.php?lang=1$ index-en.php [QSA, L]

你想:

RewriteCond %{QUERY_STRING} ^lang=1$ 
RewriteRule ^index\.php$ index-en.php? [L]

您也不希望括号内有空格。它会混淆mod_rewrite并让它认为重写标志以,结尾。