为什么我的favicon链接不起作用?

use*_*357 6 html favicon

我使用这种格式链接到我的favicon.

我的favicon.ico文件与我的HTML文件位于同一目录中,但由于某种原因,当我将其上传到我的Web服务器时它不会出现.我清除了缓存,关闭了我的浏览器,然后重新打开它,但仍然没有显示图标.

如果有人能解释为什么会这样,我会非常感激.

<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
Run Code Online (Sandbox Code Playgroud)

编辑:此外我不知道这是否会影响它,但我的网络服务器上有一个默认的图标.我不知道是否有可能覆盖这个.

编辑2:不确定这是否有所作为,但这是我头脑的基本结构.

<head>
        <meta charset="utf-8">
        <meta name="author" content="">
        <meta name="description" content="Home">

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

        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />  
    </head>
Run Code Online (Sandbox Code Playgroud)

小智 7

根据这个答案,看起来它应该是rel="icon"代替rel="shortcut icon".

此外,如果您favicon.ico位于服务器的根目录http://example.com/favicon.ico并且您的页面位于子目录中http://example.com/blog/,则浏览器将尝试在favicon.ico当前目录中搜索http://example.com/blog/favicon.ico,这将导致404错误; 为了避免这种情况,你应该设置href="/favicon.ico"它总是指向根目录,无论你在哪个子目录中.