为什么我的`favicon.ico`的要求不工作? [英] Why is my `favicon.ico` request not working?

查看:1025
本文介绍了为什么我的`favicon.ico`的要求不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的favicon.ico 在我的网站。

在HTML中,我链接到它的位置...

In the HTML, I link to its location...

<link rel="icon" href="/assets/images/layout/favicon.ico" type="image/x-icon" />

我也有这样的我的.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]

...到 /favicon.ico 请求重定向到不同的位置。

...to redirect the /favicon.ico requests to a different location.

出于某种原因,每次我要求 的favicon.ico 在我的浏览器,我得到 304未修改匹配ETag时和响应的显然的空白图像,即使 /assets/images/layout/favicon.ico 确实的存在。

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.

这是怎么回事呢?是什么原因造成这种 304

What is going on here? What is causing this 304?

推荐答案

首先,我宁愿把这个规则在.htaccess这样的:

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 内部重定向 /assets/images/layout/favicon.ico

我已经在IE,Firefox和Chrome,所有3测试显示这此行为的第一次(或清除缓存后),我得到 200 的的favicon.ico但事后所有的浏览器缓存这个图标文件,也懒得去发送另一个请求到服务器。有了这个设置,我没有找到任何 304 发生在我的测试。

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.

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"

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)"

火狐

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"

这篇关于为什么我的`favicon.ico`的要求不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆