如何添加负RewriteCond条件?

时间:2013-10-12 08:42:14

标签: regex .htaccess mod-rewrite url-rewriting rewrite

我需要为以下重写规则添加额外条件:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

如果网址中有“/ eng /”,那么我不希望这次重写发生?我怎样才能添加这种条件?

1 个答案:

答案 0 :(得分:0)

这是:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^((?!eng/).+?)/?$ $1.php [L,NC]

或者其他:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule !^eng/ %{REQUEST_URI}.php [L,NC]