我的网站上需要有图标吗?如何消除我在 apache 日志中看到的错误?
我不断在我的 apache 日志中看到 favicon 警告。我该如何摆脱这些?我的网站必须有图标吗?
I keep seeing favicon warnings in my apache log. How do I get rid of those? Do I have to have a favicon for my site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
/favicon.ico
是浏览器黑暗时代 (cca 2000) 的产物之一。虽然无法阻止浏览器请求,但创建名为 favicon.ico 的 0 字节文件会结束 404 错误流(因为该文件存在),但浏览器不会为您的站点显示任何 favicon。/favicon.ico
is one of the artifacts of the Browser Dark Ages (cca 2000). While there is no way to prevent the browser requests, creating a 0-byte file named favicon.ico ends the flow of 404 errors (as the file exists), but no favicon will be shown by the browsers for your site.Johan Petersson 在 http 上提供了一个很好的答案,可以在不使用图标的情况下防止文件未找到错误://www.trilithium.com/johan/2005/02/no-favicon/
将以下代码放在 httpd.conf 的虚拟主机部分(或您定义站点环境的任何位置),应该会停止错误出现在 Apache 错误日志中:
或者,您可以创建一个空白文件并将其命名为 favicon.ico,并将其放置在站点的根目录中。
Johan Petersson provides a good answer to preventing file not found errors without using a favicon at http://www.trilithium.com/johan/2005/02/no-favicon/
Placing the following code in the Virtual Host section of httpd.conf (or wherever you define your site environment), should stop the errors appearing in the Apache error log:
Alternatively, you can create a blank file and name it favicon.ico, placing it in the root directory of the site.
您不需要,不,但某些浏览器会自动请求
/favicon.ico
,因此错误几乎是不可避免的。You don't need to, no, but some browsers will request
/favicon.ico
automatically, so the errors are pretty much unavoidable.您实际上并不需要它,但正如其他人所说,即使
中未指定,某些浏览器也会要求它。
我不是专家,但我玩过 mod_rewrite位,这就是你可以做的:
我只在我的本地主机上尝试过这个:第一个请求导致 410,但对于所有后续请求,浏览器不会要求该文件,因为它记得它已经消失了。
我不确定这就是您应该如何使用 410 GONE 状态的方式,也不确定它是否能 100% 工作。
You don't really need it, but as others have said, some browsers will ask for it even if it's not specified in
<link rel="shortcut icon" />
.I'm not an expert, but I played with mod_rewrite a bit, and here's what you can do:
I only tried this on my localhost: first request resulted in 410, but for all following ones, browser does not ask for that file, because it remembers it's gone.
I'm not sure this is how you're supposed to use 410 GONE status, nor that it will work 100%.
网络浏览器使用它来显示您在收藏夹中看到的图像以及选项卡的图标。例如,当您转到 stackoverflow 时,您在选项卡中看到的很酷的图标如下所示: 我的浏览器会自动获取( chrome)使用网址: https://stackoverflow.com/favicon.ico 。它非常标准,所以如果您不希望它出现在日志中,您应该在 httpdocs 中放置一些图标并将其重命名为 favicon.ico。
Webbrowsers use this to display the image you see in your favorites as well as the icon of your tab. e.g. when you go to stackoverflow the cool icon you see in the tab as shown : is automatically fetched by my browser (chrome) using the url : https://stackoverflow.com/favicon.ico . Its pretty standard so in case you don't want it in your log you should put some icon and rename it as favicon.ico in the httpdocs.
查看日志,您可能会看到这样的 404 错误:
favicon.ico
:Internet Explorer、Chrome...apple-touch-icon.png
:iOS 设备、Android ,也许还有一些其他设备apple-touch-icon-precomposed.png
:iOS 设备、Android,也许还有一些其他设备apple-touch-icon-76x76.png
:iOS、可能是其他一些设备apple-touch-icon-120x120.png
:iOS,可能是其他一些设备apple-touch-icon-152x152.png
:iOS,可能是其他一些设备如果您绝对不想向您的网站添加网站图标,您可以应用其他答案中描述的解决方案之一:
然而,网站图标现在非常常见,您可能想向您的网站添加一个网站图标。这个 favicon 生成器 一次创建所有这些文件。全面披露:我是该网站的创建者。
Looking at your logs, you will probably see such 404 errors:
favicon.ico
: Internet Explorer, Chrome...apple-touch-icon.png
: iOS devices, Android, maybe some other devicesapple-touch-icon-precomposed.png
: iOS devices, Android, maybe some other devicesapple-touch-icon-76x76.png
: iOS, maybe some other devicesapple-touch-icon-120x120.png
: iOS, maybe some other devicesapple-touch-icon-152x152.png
: iOS, maybe some other devicesIf you absolutely don't want to add a favicon to your site, you can apply one the the solution described in the other answers:
However, favicon are so common nowadays that you probably want to add one to your site. This favicon generator creates all these files at once. Full disclosure: I am the creator of this site.
并不是真的需要它。
但是它在您的网站上使用(警告)。
检查您网站的来源,看看它是否包含:
在页面的标题部分。
删除该行或添加图标以防止日志中出现错误。
Not really need it.
However it is used on your site (the warnings).
Check the source of your website to see if it contains:
In the head section of the page.
Remove that line or add the favicon to prevent erros in your log.