HTACCESS处理2个RewriteRules

时间:2014-07-31 10:45:21

标签: regex apache .htaccess mod-rewrite

RewriteEngine On
Options +FollowSymLinks
RewriteBase /

RewriteRule ^api/people/([^/]*)$ api/people.php?id=$1

RewriteRule ^api/people/([^/]*)/([^/]*)$ api/people.php?action=$1&id=$2

在上面的示例中,有RewriteRules个人检测到网址是否为domain.com/api/people/1而另一个检测到domain.com/api/people/settings/1

当我尝试访问后一个url时,我通常会得到Error 500,有没有办法整理HTACCESS以便它可以检测到url是第一个还是最后一个?

1 个答案:

答案 0 :(得分:0)

保持你的.htaccess像这样:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^api/people/([^/]+)/?$ api/people.php?id=$1 [L,QSA]

RewriteRule ^api/people/([^/]+)/([^/]+)/?$ api/people.php?action=$1&id=$2 [L,QSA]