Question

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.

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top