Apache 重写:%{HTTP_HOST} 目录中的网站图标
我的软件支持指向完全相同目录的多个域,我使用共享托管。我需要从具有各自主机名的目录加载每个域的图标。这是一个视觉效果...
http://www.example1.com/favicon.ico
public_html/www.example1.com/favicon.ico
\
http://www.example2.com/favicon.ico
public_html/www.example2.com/favicon.ico
\
http://www.example3.com/favicon.ico
public_html/www.example3.com/favicon.ico
我已经尝试过一些类似这样的重写,但没有成功...
RewriteEngine on
RewriteRule ^favicon\.ico$ %{HTTP_HOST}/favicon\.ico
要记住的事情...
1.) 我使用共享托管,所以请记住我需要的答案应该是简短而简单。
2.) 我只会接受动态答案,我只会使用 %{HTTP_HOST} 变量,而不是静态域名,因为我不会每次添加域名时都手动编辑 .htaccess 文件。
3.)我可能最终会在这些子目录中放置一个 .htaccess 文件,尽管我目前没有这样做,但如果我没有必要接受答案,那么 favicon 的例外将不胜感激。
4.) 我非常乐意做出任何澄清。
My software supports multiple domains pointed at the exact same directory, I use shared hosting. I need to have each domain's favicon load from directories with their respective host names. Here is a visual...
http://www.example1.com/favicon.ico
public_html/www.example1.com/favicon.ico
\
http://www.example2.com/favicon.ico
public_html/www.example2.com/favicon.ico
\
http://www.example3.com/favicon.ico
public_html/www.example3.com/favicon.ico
I've tried some rewrites along the lines like this without any success...
RewriteEngine on
RewriteRule ^favicon\.ico$ %{HTTP_HOST}/favicon\.ico
Things to keep in mind...
1.) I use shared hosting so remember that the answer I need should be short and simple.
2.) I will only accept a DYNAMIC answer, I will only use the %{HTTP_HOST} variable and NOT a static domain name as I will not be manually editing my .htaccess file every single time I add a domain name.
3.) I may end up putting a .htaccess file in those sub-directories though I do not at the moment, an exception for the favicon would be greatly appreciated though is not necessary for me to accept the answer.
4.) I'll be more than happy to make any clarifications.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用此代码:
Use this code:
我也一直在努力解决这个问题,但我最终使用以下规则修复了它:
我将其填充到虚拟主机声明中。您可以为每个虚拟主机执行此操作,您所需要做的就是将第二部分指向正确的图标!
这解决了我所有的图标问题,甚至对于 Firefox 也是如此:)
(在 FF25、Safari 6.1、IE8 和 IE10 上测试)
I have been struggling with this issue too but I finally fixed it using the following rule:
I stuffed this into a virtual host declaration. You can do this for each of your virtual hosts, all you need to do is point the second part to the correct icon!
This solves all of my favicon problems, even for Firefox :)
(Tested on FF25, Safari 6.1, IE8 and IE10)
这个对我来说效果更好
This one worked better in my case
为了支持所有可能的浏览器和平台,除了
favicon.ico
文件外,还需要有android-chrome-192x192.png
、apple-touch等文件-icon.png
、favicon-32x32.png
等...这是支持所有这些的重写规则:
这将提供包括 Apple Touch、Android Chrome、Windows 和其他 favicons 在内的 favicons从
/favicons/
文件夹。To support all possible browsers and platforms, in addition to
favicon.ico
file, need to have files such asandroid-chrome-192x192.png
,apple-touch-icon.png
,favicon-32x32.png
, etc...Here is rewrite rule to support them all:
This will serve favicons including Apple Touch, Android Chrome, Windows and other favicons from
/favicons/<DOMAIN_NAME>
folder.我在子域上的文件中遇到了 favicon 问题,
很长一段时间以来,我一直在努力为 htaccess 中的 favicon 重定向仅一个子域。
我的情况是所有域都从 public/ 目录中获取 favicon。一个子域(我们称之为“subdomain_a”)被配置为从另一个目录获取它并且它可以工作。
在 subdomain_a 上打开文件时出现问题。文件视图(fe pdf-viewer)中的图标是从 public/ 目录中获取的,而不是从 subdomain_a 的配置中获取的。
这是我的解决方案:
I had a problem with favicon in files on subdomain
I was struggling with redirect for favicon in htaccess for only one subdomain for a long time.
My case was that all domain take favicon from public/ directory. One subdomain (let's call it 'subdomain_a') is configured to take it from another directory and it works.
Problem appeared when a file was opened on subdomain_a. The favicon in file view (f.e. pdf-viewer) was taken from public/ directory, not from configuration of subdomain_a.
Here is my solution: