douqulv6059 2011-06-26 20:13 采纳率: 0%
浏览 83
已采纳

Apache mod_rewrite:我做错了什么?

I've got a really simple rewrite in my .htaccess file, but it doesn't exactly work the way I want. This is my code:

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

Basically what I want is that every page is like this: /0/title. The title is just to make the URL clearer for the user, but the number (id) should be passed to my PHP script. With this code the id is not passed to my index.php script. It is passed to that script if I just remove ".*" from the fourth row, but then URL's with text after the number don't get passed to my index.php file.

What am I doing wrong? How can I fix this?

Thanks!

  • 写回答

1条回答 默认 最新

  • douhui8454 2011-06-26 20:16
    关注

    You are trying to trap URL's like /0/title, but you don't have a slash / in your match pattern. Try this instead:

    # Should match /01234/anything
    # with the "/anything" optional
    RewriteRule ^([0-9]+)(/.*)?$ index.php?id=$1 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?