简体   繁体   中英

URL Rewrite blanket redirect with directory exceptions

I have a website that employs a generic mod_rewrite rule to push all requests to the index.php page, with the exception of certain file extensions:

RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml)$ index.php

What I need to be able to do is also exclude a certain directory (including any files or sub-directories contained within) from this rule - what is the best solution?

Here is my full .htaccess file, in case something else within it is intefering:

RewriteEngine ON
RewriteCond %{HTTP_HOST} !^www\..*
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST} ^([^.]*)\.(co\.uk)
RewriteRule ^.*$     http://www.%1.%2%{REQUEST_URI} [R=permanent,L]

AddHandler application/x-httpd-php .phtml

RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml)$ index.phtml

php_value display_errors "On"

Before the line you have quoted, for a directory named 'style' for instance, you need:

RewriteRule  ^style/  -  [L]

The hyphen means 'no redirection', and the '[L]' means 'last rule', as in don't carry on trying to match the URL to the follwing rules. You can put as many of these lines in as you like, but they must be before the line you give in the question.

对于任何与现有文件名不匹配的请求,您可以使用RewriteCond %{REQUEST_FILENAME} !-f进行检查。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM