Favicon in subdirectory all subdomain

2019-02-22 00:16发布

I am used to just save the favicon.ico in the public_html folder for adding the favicon.

The problema I have now is that I want to display the in all the files of a certain subdirectory, ( example.com/example "onwards" ) just putting it there, doesnt seem to do the job.

I know I could go document by document and add:

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

But I hope there is a more practical way, first I thought there might be a way trough CSS but that doesnt seem to be the case.

This would have come in handy because every document already includes:

<link rel="stylesheet" type="text/css" href="test.css" />

So any ideas or workarounds to how to solve this?

5条回答
狗以群分
2楼-- · 2019-02-22 00:42

You will have to specify the favicon using the link rel=... notation.

Browsers will search only in the root directory of the domain for a default /favicon.ico. Any variations from that you have to specify explicitly.

查看更多
戒情不戒烟
3楼-- · 2019-02-22 00:42

redirect favicon.ico url for all subdomains to public_html's favicon.ico

ie. subdomain.website.com/favicon.ico should go to www.website.com/favicon.ico

查看更多
Melony?
4楼-- · 2019-02-22 00:51

It might not be the most elegant way, and i came here to find a solution. Unfortunaly the given answers did not suited for me.

In my case i working on a localhost (via private ip)

this is what i did :

        <link rel="icon" href="<?php echo rtrim($_SERVER['PHP_SELF'], basename($_SERVER['PHP_SELF'])); ?>favicon.ico" type="image/x-icon">
查看更多
聊天终结者
5楼-- · 2019-02-22 00:54

As mentioned above don't waste time on searching. is the only way in that case. When you will be checking out results of your markup changes, remember that browser cache can be tricky.

查看更多
女痞
6楼-- · 2019-02-22 01:03

Adding the <link> element is the right way to go. Use a template engine (e.g. Template-Toolkit) to avoid duplicating common content manually.

查看更多
登录 后发表回答