开发者

How would I write a RewriteRule to make an exception for one file

开发者 https://www.devze.com 2023-01-02 04:49 出处:网络
I currently have this in my .htaccess file: Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)\\.html$ index.php?pagename=$1&%{QUERY_STRING}

I currently have this in my .htaccess file:

Options +FollowSymLinks  
RewriteEngine On    
RewriteRule ^(.*)\.html$ index.php?pagename=$1&%{QUERY_STRING}

The the html file name is rewritten to the pagename query string.

However I'm trying to al开发者_运维百科low access to one particular static html file, so somehow I need to overwrite the rule or make an exception.

Thanks for you help.


  1. No point appending QUERY_STRING yourself; you'll leave a stray & if there isn't any, and mod_rewrite already has a tool to do it better:

    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  2. You can control a RewriteRule with a RewriteCond that precedes it. For example:

    RewriteCond %{REQUEST_URI} !^/staticpage.html$
    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  3. Another useful pattern is RewriteCond %{REQUEST_FILENAME} !-f which will bypass the following RewriteRule any time that the URL would have matched an existing regular file in the docroot.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号