.htaccess rewriteRule冲突 [英] .htaccess rewriteRule conflict

查看:81
本文介绍了.htaccess rewriteRule冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码并构建一个具有以下内容的htaccess文件:

I am writing a code and build an htaccess file which has the following contents:

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/foobar

The first rule works fine but the latter seems having conflict with the first rule. Everytime I access a url at http://example.com/category/foobar or http://example.com/author/fooauthor/ I always get a message that the page cant be found because it is still trying to open the index file.

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

Is there any possibility to get around with this?

推荐答案

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

You can set general rule in the last line:

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]   

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

This issue happened because first line support all urls

这篇关于.htaccess rewriteRule冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆