[ACCEPTED]-.htaccess redirecting when file doesn't exists-mod-rewrite

Accepted answer
Score: 12

Well, the way that you have it setup, everything 19 gets routed through index.php. If a request is made 18 for a resource that doesn't exist, it gets 17 routed through index.php. It's up to index.php to 16 realize something's not there, and return 15 a 404 error, but I'm guessing it's setup 14 so that if the url= doesn't exist, to returns 13 the home page.

You can change your rules 12 to ignore the routing for certain files, like 11 for your example:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

This would make it so nothing 10 in the /js directory will ever get routed through 9 index.php, so if someone requests a non-existing 8 file in the /js directory, they'll just get 7 the regular 404 response.


That's what 6 I want, to ignore the routing for certain 5 files (js, css, images), because then if 4 the files doesn't exists i would get the 3 normal error!

If you want to ignore all 2 images, javascript, and css, then the 2nd 1 line should be:

RewriteCond %{REQUEST_URI} !\.(png|jpe?g|gif|css|js)$ [NC]

More Related questions