Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 www.example.com/thispageexists, www.example.com/thispagedoesntexist and also www.example.com/missingfile.xml 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
1  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.