Apache mod_rewrite:我做错了什么?

时间:2011-06-26 20:13:36

标签: php apache mod-rewrite friendly-url

我的.htaccess文件中有一个非常简单的重写,但它并不完全按照我想要的方式工作。这是我的代码:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^admin/?$ admin.php [L]
    RewriteRule ^([0-9]*).*$ index.php?id=$1 [L]
</IfModule>

基本上我想要的是每个页面都是这样的:/ 0 / title。标题只是为了让用户更清楚URL,但是数字(id)应该传递给我的PHP脚本。使用此代码,id不会传递给我的index.php脚本。如果我只是从第四行中删除“。*”,那么它会被传递给该脚本,但是在数字之后带有文本的URL没有传递给我的index.php文件。

我做错了什么?我该如何解决这个问题?

谢谢!

1 个答案:

答案 0 :(得分:4)

您正试图捕获/0/title之类的网址,但您的匹配模式中没有斜杠/。试试这个:

# Should match /01234/anything
# with the "/anything" optional
RewriteRule ^([0-9]+)(/.*)?$ index.php?id=$1 [L]