.htaccess url-rewrite if file not exists - how to deal with favicon.ico?

Viewed 689

I'm building my own URL shortening website and I use this as my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /go.php [L]
</IfModule>

This should redirect any URL (that is not a file) to go.php, for the URL redirection.

The problem is:

When I go to example.com/keyword, I get the go.php page. Then, I extract the keyword with:

$url = $_SERVER['REQUEST_URI'];
$keyword = strtok($url, '?');
$keyword = ltrim($keyword,"/");

Then I insert the current keyword and its referrer ($_SERVER['HTTP_REFERER]) to the log table in the database.

Everything seems to work just fine, but in my log table there are two new rows instead of one: one with the correct keyword example, and one with the keyword favicon.ico and http://example.com/keyword as the referrer.

What's exactly happening here? I need only the first and correct row. Does this problem happen only with favicon.ico? How can I fix this?

Thank you!

2 Answers
Related