.htaccess中的多个mod_rewrite规则?

时间:2013-08-05 15:17:09

标签: .htaccess mod-rewrite

我的.htaccess

中有以下内容
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /rewrite/index.php?pages=$1 [L] 

重写所有不存在的文件和目录非常有用。 但现在我需要做另一个更具体的重写

条件应为"如果请求的URI不存在,则以与会者/"结束。然后应用RewriteRule ^(。+)$ /rewrite/attendees.php?pages=$1 [L]

如何应用?

起初我以为会按照列表的顺序阅读并尝试:

RewriteCond %{REQUEST_FILENAME} employee   [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /rewrite/attendees.php?pages=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /rewrite/index.php?pages=$1 [L] 

但失败了......


解决了这个问题:

RewriteCond %{REQUEST_URI} (employee) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /rewrite/employee.php?pages=$1 [L]   

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /rewrite/index.php?pages=$1 [L]

1 个答案:

答案 0 :(得分:0)

只需添加另一个RewriteCond

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} attendees/$
RewriteRule ^(.+)$ /rewrite/index.php?pages=$1 [L]