mod_rewrite url for everything except 1) real files, and 2) specific extensions like .js, .jpg, etc

I want to route everything to my controller index.php. So far so good. Now my problem is that if I link to a resource that doesn't exist like "http://domain.com/somefile.js", my system will route this through index.php thinking it's a valid URL when what I really want is to get a 404 for specific file types.

This is what I have (see code box below). And I want to prevent js, png, jpg, gif, mp3, swf files from getting rewritten.

Any ideas?

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Open in new window

LVL 2
poisaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

babuno5Commented:
>>And I want to prevent js, png, jpg, gif, mp3, swf files from getting rewritten.

Use this condition
RewriteCond /home/httpd/html/%{REQUEST_FILENAME} !-f
if your document root is /home/httpd/html/

Use this condition
RewriteCond /home/httpd/htdocs/%{REQUEST_FILENAME} !-f
if your document root is /home/httpd/htdocs/


Rick_AtreidesCommented:
Try add another rewrite condition to you rule.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} ! \.(js|png|jpg|gif|mp3|swf)$  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
poisaAuthor Commented:
Rick,

There shouldn't be a space between the ! and the rest of the regexp. I fixed that and everything worked perfectly!

Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.