HTAccess重写规则冲突?

时间:2014-10-20 09:43:39

标签: php .htaccess url mod-rewrite redirect

我有两个重写规则,一个作为虚荣网址,例如domain.com/url和一个编辑一些数据即帖子。

出于某种原因,只有第一条规则正在发生,而不是两者都是

为什么会这样,我该如何解决?

这里的守则

RewriteEngine On

# Make sure you only match on files/directories that don't actually exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
# Rewrite the first part after the `/` into a `username` parameter

RewriteRule ^(.+)$ groups/index.php?gname=$1 [L,QSA]


RewriteRule ^edit/id/([0-9]+)/?$ groups/view_update.php?pid=$1 [NC,QSA,L]

1 个答案:

答案 0 :(得分:0)

RewriteCond仅适用于下一个RewriteRule,不适用于所有RewriteRule。还要更改规则的顺序。

将您的代码更改为:

RewriteEngine On
# Make sure you only match on files/directories that don't actually exist
RewriteBase /
# Rewrite the first part after the `/` into a `username` parameter

# skip all rewrite rules for file or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^edit/id/([0-9]+)/?$ groups/view_update.php?pid=$1 [NC,QSA,L]

RewriteRule ^(.+)$ groups/index.php?gname=$1 [L,QSA]