Link to home
Start Free TrialLog in
Avatar of poisa
poisaFlag for Canada

asked on

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

Avatar of babuno5
babuno5
Flag of India image

>>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/


ASKER CERTIFIED SOLUTION
Avatar of Rick_Atreides
Rick_Atreides

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of poisa

ASKER

Rick,

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

Thanks!