1

I've implemented a .htaccess file on my website that consists of a rewrite rule for all requests. I would like to add a condition so that when a certain file is requested the rewrite rule is not applied. How can I do this and in a way that would allow me to add more in the future if need be. I will paste my code below.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
4

1 回答 1

1

RewriteCond 行告诉 mod_rewrite 何时应用 RewriteRule。

正如@Niels 评论的那样-“RewriteCond %{REQUEST_FILENAME} !-f”行告诉系统如果请求是针对现有文件的,则不要执行您的 RewriteRule。

如果您希望规则普遍执行,即使文件存在,并且只是不重写特定文件,您将删除该行,并添加更具体的 RewriteCond 行。就像是:

RewriteCond %{REQUEST_FILENAME} ="Foo.html"

有关详细信息,请参阅http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

于 2013-05-30T09:01:16.707 回答