0

我需要做一个非常简单的 URL 重写,但我的 RewriteRule 不起作用。

我想要这个网址:http ://myweb.com:8080/MySite/bla?bla

变成这样:http ://myweb.com:8080/MySite/index.php

我的 .htaccess 文件内容是这样的:

RewriteEngine On
RewriteRule bla\?bla index.php

它位于“MySite”文件夹中。我可以成功地执行其他 url 重写规则,但是每当我需要编写带有问号的规则时,我就会陷入困境。

我究竟做错了什么?

4

1 回答 1

0

You need to use the %{QUERY_STRING} rewrite condition for this.

RewriteEngine On

RewriteCond %{QUERY_STRING} ^bla$
RewriteRule ^/?bla$ index.php [NC,L]

Please, note that the ? in the rewrite rule is not there to match against the ? in the query string. That part is handled completely by %{QUERY_STRING}. The [NC] just makes the rule case-insensitive and [L] marks the rule as last.

于 2013-07-17T16:25:59.307 回答