I’m using .htaccess to redirect users to my main controller and it is working fine. But when i call a js file that doesn’t exist like:
<script src="/js/jquery1231231312.js"></script>
Instead of just says 404 – file doesn’t exists, this js file is getting the content of index.php. How should i proceed?
This is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Well, the way that you have it setup, everything gets routed through
index.php. If a request is made for a resource that doesn’t exist, it gets routed throughindex.php. It’s up to index.php to realize something’s not there, and return a 404 error, but I’m guessing it’s setup so that if theurl=doesn’t exist, to returns the home page.You can change your rules to ignore the routing for certain files, like for your example:
This would make it so nothing in the
/jsdirectory will ever get routed throughindex.php, so if someone requests a non-existing file in the/jsdirectory, they’ll just get the regular 404 response.EDIT:
If you want to ignore all images, javascript, and css, then the 2nd line should be: