tags:

views:

120

answers:

3

I would like to have mod_rewrite go into effect for any filenames that don't exists except if that file name ends with js, css, gif, etc., so those would return regular 404s...

I tried this out:

RewriteCond %{REQUEST_FILENAME} \.(js|ico|gif|jpg|png|css|pdf)$ [OR]
RewriteCond %{REQUEST_FILENAME} favicon.ico$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [L]

Which I found online somewhere, but it doesn't seem to work. My non existant JS files still get routed to my index.php file.

A: 

Have you added the commands that go before the .htaccess file? Like this line?

RewriteEngine On
Chacha102
Obviously...if that wasn't there mod_rewrite wouldn't work at all!
blockhead
+1  A: 

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !.*\.(js|ico|gif|jpg|png|css|pdf)$ /index.php%{REQUEST_URI} [L]
Gumbo
Looks plausible but it still doesn't seem to work.
blockhead
Well it works for me.
Gumbo
Maybe its my server setup...I tried it on another server and it worked as advertised.
blockhead
A: 

You might want to use the [NC] flag on the first line if you can have not only .js files but also .Js or .JS or .jS files...

mihi