0

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.

4
  • Exclude from what? I don't understand the question.
    – womble
    Jul 17, 2011 at 3:59
  • No need to downvote if you don't understand. just ask
    – Moak
    Jul 17, 2011 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, 2011 at 9:40
  • And look! A good question begets a good answer in no time.
    – womble
    Jul 17, 2011 at 11:52

1 Answer 1

3

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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .