带参数的.htaccess prettyurl无法使其正常工作

时间:2014-10-09 14:01:30

标签: .htaccess pretty-urls

我试图做一个漂亮的样子 从: example.com/index.php?key=test&lang=eng 至 example.com/test/eng

我在网上搜索了很多代码示例,但我似乎无法使其正常工作。这就是我现在正在做的事情。

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\$ index.php?key=$1&lang=$2 [L]

1 个答案:

答案 0 :(得分:1)

您不想转义$符号。尝试:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+index\.php\?key=([^&]+)&lang=([^&\ ]+)
RewriteRUle ^ /%1/%2? [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?key=$1&lang=$2 [L,QSA]