I want to Set Favicon for All files in my site using htaccess ??
Asked
Active
Viewed 3.2k times
3
-
where are the current favicons? does each file point to a different one? – Matt Dodge Jun 07 '12 at 05:38
-
1Don't know how to do it from .htaccess, rather you can set it in header part of your template and call the same header on all pages – baig772 Jun 07 '12 at 05:38
-
A more detailed rewrite rule also accounting for non-favicon icons: https://stackoverflow.com/a/37107216/4378314 – Kalnode Nov 10 '19 at 14:30
5 Answers
9
Rather than specifying a Favicon in htaccess you would be better off using the following META tag within the HEAD area of every page:
<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.

Joe Spurling
- 967
- 11
- 22
-
3The benefit of the htaccess method is the OP can keep it out of the web root so not to assign it to any one site, but still deliver it on the initial request. The meta tag referencing a 'shared' domain (likely a cookieless or static asset domain) would force the browser to do a new DNS lookup and open a new http connection, and the common domain would have to support http and https because it wouldn't know which protocol the site fetching it was using. – AlienWebguy Jun 07 '12 at 05:46
-
Keep in mind it's possible some software/apps may just grab the favicon alone, earlier or exclusive of the HTML (ie never grabbing your HTML). – Kalnode Nov 10 '19 at 14:26
8
Without testing, something along these lines:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond favicon.ico
RewriteRule .* path/to/shared/favicon.ico [L]

AlienWebguy
- 76,997
- 17
- 122
- 145
7
Inspired by this thread: Rewriting path for a specific file using htaccess and using the fact that browsers will look for favicon.ico in root of site:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^favicon.ico path_to_favicon_folder/favicon.ico [L]
-
-
-
-
The relation to the subfolder from the .htaccess file is ., meaning it is in the same folder. I'm not going to chat about this again. Thank you for trying to help. – Ярослав Рахматуллин Nov 29 '15 at 02:09
1
RewriteEngine on
RewriteBase /
RewriteRule "^(.+)favicon\.ico(|\?.+)$" "/favicon.ico" [PT]

Roland Soós
- 3,125
- 4
- 36
- 49
1
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_html directory.
Please DELETE CACHE of your browser or test on a new browser.
I hope it helps.

Shahrad Elahi
- 774
- 12
- 22
-
Hi! you can edit your own answer with the comment you just wrote here. – Giulio Caccin Sep 19 '19 at 08:41