如何使用例外的htacces重写规则?

时间:2016-04-29 21:25:13

标签: .htaccess url-rewriting url-redirection

我正在尝试从

执行重写规则
http://website.com/location/new-york.php <- user goes to

http://website.com/location/city.php?name=new-york <- u use this in my code

并且根据重写规则,我认为我需要

的例外
http://website.com/location/city.php...

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用否定前瞻在此规则中为/location/目录中的.htaccess创建例外:

RewriteEngine On
RewriteBase /location/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!city\.php$)(.+?)(?:\.php)?$ city.php?name=$1 [L,QSA,NC]