Search code examples
php.htaccessurl-routingfavicon

Whats wrong with my .htaccess? Still tries to load file as a controller. Custom MVC PHP


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php

It tries to load a /favicon.ico as a controller because favicon.ico does not exist in my root folder. How would I rewrite the above htaccess to not load favicon.ico as a controller but to ignore it?

It is making an extra request which I do not want it to do.


Solution

  • You can add this to your htaccess to ignore rewriting favicon.ico and anything with the extensions in the parens

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

    So your htaccess would look like

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|ico)$ [NC]
    RewriteRule ^(.*)$ /index.php