0

我的网址如下所示:

http://127.0.0.1/website/comments.php?topic_id=16

我想让它看起来像这样:

http://127.0.0.1/website/comments/my-news-article/16.php

我已经应用了这个

RewriteEngine on
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2

我也打开Rewrite_module了Apache。

但它不起作用。

4

2 回答 2

1

始终考虑整个 URL 路径。你的包括 /website,所以:

RewriteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
于 2012-09-13T20:57:30.310 回答
0

RewriteBase 用于每个目录的指令。尝试

重写引擎开启
重写规则 ^/website/comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ /website/comments.php?topic_id=$2

为我工作。请注意,我还将行尾的查询字符串参数更改为“topic_id”。也许这是另一个错误的原因。如果仍然失败,请检查配置是否在正确的虚拟主机配置中。

于 2012-09-13T22:31:47.193 回答