我有两个重写规则,一个是作为一个虚荣的url,例如domain.com/url,另一个是编辑一些数据,也就是post。
出于某种原因,只有第一条规则发生,而不是同时发生
为什么会这样?我该怎么解决??
这是代码
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]
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]