Directory Redirection Overwrite URL

I have a website that uses the general mod_rewrite rule to direct 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 do is to exclude from this rule a specific directory (including any files or subdirectories contained inside) - the best solution?

Here is my complete .htaccess file, if anything else is inside it 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" 
+4
source share
2 answers

Before the line you specified for a directory named "style", for example, you need:

 RewriteRule ^style/ - [L] 

A hyphen means โ€œno redirectโ€, and โ€œ[L]โ€ means โ€œlast ruleโ€, as if you are not trying to match the URL with the follwing rules. You can put as many lines as you want, but they should be up to the line you asked in the question.

+7
source

You can check with RewriteCond %{REQUEST_FILENAME} !-f for any query that does not match an existing file name.

0
source

All Articles