Adding an exception for mod_rewrite

Hi, I have a mod_rewrite in my .htaccess file that is reformatting address. I already have one exception that will keep .cfg files free from the rewrite, I’m trying to do that same with .html files that contain the word “client” but have had no luck trying a number of different approaches. I’m out of my depth with .htaccess stuff unfortunately.

Here is the file currently (obviously this isn’t php, but to get code formatting this I’ve added it as such below):

RewriteEngine on

RewriteRule \\.cfg$ - [L]
RewriteRule client - [L]

RewriteCond  %{REQUEST_FILENAME}    !-f
RewriteCond  %{REQUEST_FILENAME}    !-d
RewriteRule  .* index.php 

Any help would be greatly appreciated!

Ah I see why that doesn’t work.

From the manual:

  • (dash)
    A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

The dash doesn’t stop rewriting, but only used if you want to use a flag without any rewriting (useful for skipping rules with the [S] flag for example).

That being said, you can either use the skip flag, or make the exceptions conditions of the last rule

RewriteEngine on

# if URI ends in .cfg skip the next two RewriteRules
RewriteRule .cfg$ - [L,S=2]
# if URI contains "client" skip the next RewriteRule
RewriteRule client - [L,S=1]

RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule .* index.php 


RewriteEngine on

RewriteCond %{REQUEST_URI} !\\.cfg$
RewriteCond %{REQUEST_URI} !client
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule .* index.php 

The second block would have my personal preference.

BTW, I’d change the last RewriteRule from RewriteRule .* index.php to RewriteRule .? index.php [L] – that’s a bit more efficient

Thankyou , I am using the second approach and it works well.