简体   繁体   中英

PHP - Should I add a favicon.ico to avoid a 404 error?

I read that the browser is looking automatically for a favicon.ico - is that also the case in an Android WebView element? Should I include a favicon.ico to a PHP page like below, to avoid a 404 error in my logs?

<?
//PHP CODE...
?>
<!DOCTYPE html>
<head>
<title>Hello world</title>
</head>
<body>
<--
Content...
-->
</body>
</html>

This happens because (almost every) browser searches for a favicon by default. If the accessed page don't inform a valid URL for it, Apache uses the root directory.

You have two choices. You can create a website icon for each of your websites, or you tell Apache not to log that event as an error message.

1).

If you choose the second option, add the following code to each VirtualHost, or at least the ones which don't have a favicon file:

Redirect 404 /favicon.ico
<Location /favicon.ico>
   ErrorDocument 404 "No favicon"
</Location>

2).

There is no way to stop browsers requesting it. You can either create a favicon, or create a zero byte file called favicon.ico and place in the web root.

Yes, you can add an empty favicon.ico file. But of course the file itself, in the document root of your site, but not just a link in HTML code.

将favicon放在文档根目录上会更好。

只需将虚拟或空白的favicon文件放入页面即可。如果在favicon选择器中保留空白路径,有时会出错。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM