Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a set of rewrite rules that redirect all pages that don't exist to the index of my site:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Basically, the current rule is redirecting every URL that is not a directory or file to index.php, so, and also go to the index.php page. If the URL doesn't exist in the CMS, that will trigger a 404 error back to the user.

I'd like to exclude any URL with certain file extensions, say .(js|css|ico|gif|jpg|png|xml|html|swf|ttf|eot)$, from being redirected, even if the file does not exist.

I still want to continue directing pages that don't exist to index.php but not if the url ends in any of those file extensions.

share|improve this question
Exclude from what? I don't understand the question. – womble Jul 17 '11 at 3:59
No need to downvote if you don't understand. just ask – Moak Jul 17 '11 at 9:24
Or you could ask a comprehensible question to begin with. Does my edit of the question represent what you want to achieve? – womble Jul 17 '11 at 9:40
Yes it does, thanks – Moak Jul 17 '11 at 10:39
And look! A good question begets a good answer in no time. – womble Jul 17 '11 at 11:52
up vote 3 down vote accepted

The rule is simple:

RewriteRule \.(js|css|ico|gif|jpg|png|xml|html|swf|ttf|eot)$ - [NC,L]

Just place it in a right place (as order of rules matters): for example, before this line: RewriteRule ^.*$ index.php [NC,L]

P.S. The [NC] flag is unnecessary for your rules with such (^.*$) pattern (it makes no difference at all).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.