Why Is My `favicon.ico` Request Not Working?
I have a favicon.ico
on my site.
In the HTML, I link to its location...
<link rel="icon" target="_blank" rel="nofollow noreferrer" href="/assets/images/layout/favicon.ico" type="image/x-icon" />
I also have this in my .htaccess
.
# Redirect /favicon.ico requests
RewriteCond %{REQUEST_URI} !^assets/images/layout/favicon\.ico [NC]
RewriteCond %{REQUEST_URI} ^favicon\.(gif|ico|png|jpe?g)$ [NC]
RewriteRule ^(.*)$ assets/images/layout/favicon.ico [R=301,L]
...to redirect the /favicon.ico
requests to a different location.
For some reason, every time I request favicon.ico
in my browser, I get 304 Not Modified
response with matching Etags and apparently a blank image, even though /assets/images/layout/favicon.ico
does exist.
I get the same issue when trying to access it wil the full path.
What is going on here? What is causing this 304
?
Answer
First of all I would rather put this rule in .htaccess like this:
RewriteRule ^favicon\.(gif|ico|png|jpe?g)$ /assets/images/layout/favicon.ico [L,NC]
Then if you have this in your web page:
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
/favicon.ico
will be internally redirected to /assets/images/layout/favicon.ico
I have tested this in IE, Firefox and Chrome and all 3 show this behavior that for the first time (or after clearing cache) I get 200
for favicon.ico but afterwards all browsers cache this icon file and don't bother to send another request to the server. With this setup I didn't find any 304
happening in my testing.
My access log:
Chrome
127.0.0.1 - - [05/May/2011:23:58:15 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.24 (KHTML, like Geck
o) Chrome/11.0.696.60 Safari/534.24"
IE
127.0.0.1 - - [06/May/2011:00:05:18 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .
NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
Firefox
127.0.0.1 - - [06/May/2011:00:07:33 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
Related Questions
- → .htaccess - not routing to public folder
- → Laravel 4.2 application occurs unnecessary redirection after uploading live server
- → Htaccess negation
- → Building sitemap for 2 wordpress install under 1 domain
- → htaccess not working properly for sub url having more slashes
- → How to give access execute specific php file in server?
- → 301 Redirection from no-www to www in wordpress
- → Cyclical redirection at the start laravel 5 project
- → Can't route in Laravel framework
- → codeigniter seo url with htaccess
- → PHP Seo Friendly URL
- → Convert URL to SEO Friendly
- → IP Canonicalization (WordPress)