我的网站上需要有图标吗?如何消除我在 apache 日志中看到的错误?

发布于 2024-10-04 01:54:02 字数 58 浏览 8 评论 0原文

我不断在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

怪我入戏太深 2024-10-11 01:54:02

/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.

我恋#小黄人 2024-10-11 01:54:02

Johan Petersson 在 http 上提供了一个很好的答案,可以在不使用图标的情况下防止文件未找到错误://www.trilithium.com/johan/2005/02/no-favicon/

将以下代码放在 httpd.conf 的虚拟主机部分(或您定义站点环境的任何位置),应该会停止错误出现在 Apache 错误日志中:

# Don't bother looking for favicon.ico
Redirect 404 /favicon.ico

# Don't bother sending the custom error page for favicon.ico
<Location /favicon.ico>
    ErrorDocument 404 "No favicon
</Location>

或者,您可以创建一个空白文件并将其命名为 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:

# Don't bother looking for favicon.ico
Redirect 404 /favicon.ico

# Don't bother sending the custom error page for favicon.ico
<Location /favicon.ico>
    ErrorDocument 404 "No favicon
</Location>

Alternatively, you can create a blank file and name it favicon.ico, placing it in the root directory of the site.

本王不退位尔等都是臣 2024-10-11 01:54:02

您不需要,不,但某些浏览器会自动请求 /favicon.ico,因此错误几乎是不可避免的。

You don't need to, no, but some browsers will request /favicon.ico automatically, so the errors are pretty much unavoidable.

树深时见影 2024-10-11 01:54:02

您实际上并不需要它,但正如其他人所说,即使 中未指定,某些浏览器也会要求它。

我不是专家,但我玩过 mod_rewrite位,这就是你可以做的:

# turn on the mod_rewrite module
RewriteEngine On
# if requested file is not an existing file
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
# and it's name is favicon.ico, send an empty 410 GONE response to the browser
RewriteRule .*favicon\.ico$ - [G] 

我只在我的本地主机上尝试过这个:第一个请求导致 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:

# turn on the mod_rewrite module
RewriteEngine On
# if requested file is not an existing file
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
# and it's name is favicon.ico, send an empty 410 GONE response to the browser
RewriteRule .*favicon\.ico$ - [G] 

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%.

眼泪都笑了 2024-10-11 01:54:02

网络浏览器使用它来显示您在收藏夹中看到的图像以及选项卡的图标。例如,当您转到 stackoverflow 时,您在选项卡中看到的很酷的图标如下所示: alt text 我的浏览器会自动获取( 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 : alt text 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.

清风不识月 2024-10-11 01:54:02

查看日志,您可能会看到这样的 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,可能是其他一些设备

如果您绝对不想向您的网站添加网站图标,您可以应用其他答案中描述的解决方案之一:

  • mod_rewrite
  • Force 404
  • Empty picture

然而,网站图标现在非常常见,您可能想向您的网站添加一个网站图标。这个 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 devices
  • apple-touch-icon-precomposed.png: iOS devices, Android, maybe some other devices
  • apple-touch-icon-76x76.png: iOS, maybe some other devices
  • apple-touch-icon-120x120.png: iOS, maybe some other devices
  • apple-touch-icon-152x152.png: iOS, maybe some other devices

If you absolutely don't want to add a favicon to your site, you can apply one the the solution described in the other answers:

  • mod_rewrite
  • Force 404
  • Empty picture

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.

汹涌人海 2024-10-11 01:54:02

并不是真的需要它。

但是它在您的网站上使用(警告)。

检查您网站的来源,看看它是否包含:

<link rel="shortcut icon" href="favicon.ico">

在页面的标题部分。

删除该行或添加图标以防止日志中出现错误。

Not really need it.

However it is used on your site (the warnings).

Check the source of your website to see if it contains:

<link rel="shortcut icon" href="favicon.ico">

In the head section of the page.

Remove that line or add the favicon to prevent erros in your log.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文