.htaccess rewriteRule冲突

时间:2016-08-17 07:24:09

标签: php apache .htaccess mod-rewrite

我正在编写代码并构建一个htaccess文件,其中包含以下内容:

RewriteEngine on

RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    index.php?id=$1    [NC,L]    # Handle page requests
RewriteRule    ^category/([A-Za-z0-9-]+)/?$    category.php?cat=$1    [NC,L]    # Handle category requests
RewriteRule    ^author/([A-Za-z0-9-]+)/?$    author.php?auth=$1    [NC,L]    # Handle author requests

第一条规则运作正常,但后者似乎与第一条规则发生冲突。每次我在http://example.com/category/foobarhttp://example.com/author/fooauthor/访问网址时,我总会收到一条消息,指出该页面无法找到,因为它仍在尝试打开索引文件。

有没有可能解决这个问题?

1 个答案:

答案 0 :(得分:2)

您可以在最后一行设置常规规则:

RewriteEngine on

RewriteRule    ^category/([A-Za-z0-9-]+)/?$    category.php?cat=$1    [NC,L]    
RewriteRule    ^author/([A-Za-z0-9-]+)/?$    author.php?auth=$1    [NC,L]  
RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    index.php?id=$1    [NC,L]   

发生此问题是因为第一行支持所有网址

相关问题