简单的重写规则不起作用

我有以下url:

http://www.mysite.com/test/index.php?topic=rules 

我想重写它:

 http://www.mysite.com/test/topic/rules 

我尝试了以下内容:

 Options +FollowSymLinks RewriteEngine On RewriteRule ^topic/([a-zA-Z0-9]+)/$ index.php?topic=$1 

没有做任何事情。 我用第三方网站来生成这个重写代码,所以也许这是不正确的,我不知道。 Apache中是否有任何东西可能导致此问题无法正常工作?

你错过了URL中的/test/ 。 领导^你的规则意味着“path的开始”。 你可能想要:

 Options +FollowSymLinks RewriteEngine On RewriteRule ^/test/topic/([a-zA-Z0-9]+)/$ /test/index.php?topic=$1 

或类似的东西。

你不能匹配RewriteRule中的查询string,所以你需要使用RewriteCond。

 RewriteCond %{QUERY_STRING} topic=(.*) RewriteRule test/index.php test/topic/%1? [L]