php 如何使用 htaccess 为所有页面设置 favicon 默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10926207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set favicon default for all pages using htaccess
提问by Arshpreet Wadehra
I want to Set Favicon for All files in my site using htaccess ??
我想使用 htaccess 为我站点中的所有文件设置 Favicon ??
回答by AlienWebguy
Without testing, something along these lines:
未经测试,以下内容:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond favicon.ico
RewriteRule .* path/to/shared/favicon.ico [L]
回答by Joe Spurling
Rather than specifying a Favicon in htaccess you would be better off using the following META tag within the HEAD area of every page:
与其在 htaccess 中指定 Favicon,不如在每个页面的 HEAD 区域内使用以下 META 标记:
<link rel="shortcut icon" href="http://example.com/myicon.ico" />
If this is not possible (perhaps you have a very large static website) you can simply store the file (name it favicon.ico) in your website's root folder (e.g. /public_html/) as browsers will automatically look there first.
如果这是不可能的(也许您有一个非常大的静态网站),您可以简单地将文件(将其命名为 favicon.ico)存储在您网站的根文件夹(例如 /public_html/)中,因为浏览器会自动首先查看那里。
回答by Vidde
Inspired by this thread: Rewriting path for a specific file using htaccessand using the fact that browsers will look for favicon.ico in root of site:
受此线程的启发:使用 htaccess 重写特定文件的路径并使用浏览器将在站点根目录中查找 favicon.ico 的事实:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^favicon.ico path_to_favicon_folder/favicon.ico [L]
回答by Roland Soós
RewriteEngine on
RewriteBase /
RewriteRule "^(.+)favicon\.ico(|\?.+)$" "/favicon.ico" [PT]
回答by Shahrad Elahi
Add this code
添加此代码
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond favicon.ico
RewriteRule .* favicon.ico [L]
If top code is not going to work use this.
如果顶级代码不起作用,请使用它。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^(.+)favicon\.ico(|\?.+)$" "/favicon.ico" [PT]
You must put your favicon in public_htmldirectory.
您必须将您的图标放在public_html目录中。
Please DELETE CACHEof your browser or test on a new browser.
请删除浏览器的缓存或在新浏览器上测试。
I hope it helps.
我希望它有帮助。

