htaccess references favicon file, move the file to root?

Bobby
Bobby used Ask the Experts™
on
In my .htaccess file, there are references to favicon. I want to delete my graphics folder. Is it of to move any favicon files to the root of my site, not inside a folder?

#do things different on prod
<IfDefine prod>
RewriteRule ^favicon\.ico$ /graphics/live_favicon.ico [L]
</IfDefine>
<IfDefine !prod>
RewriteRule ^favicon\.ico$ /graphics/test_favicon.ico [L]
</IfDefine>

and where is "prod" defined? Is that an Apache thing? Sorry for the newbness, Im taking over for a departed employee and trying to sort things out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
If you move the two ico files to the root folder, use change it to this:

#do things different on prod
<IfDefine prod>
RewriteRule ^favicon\.ico$ /live_favicon.ico [L]
</IfDefine>
<IfDefine !prod>
RewriteRule ^favicon\.ico$ /test_favicon.ico [L]
</IfDefine>

Open in new window


The prod line (<IfDefine prod> and hence also <IfDefine !prod>) checks if that variable is set or not (could be checking if it's part of the domain or url). Check for the definitive meaning by searching it in the rest of the htaccess file.

Author

Commented:
Is "prod" an Apache thing? Where is it defined, or did we make that up ourselves?

And would it be /live_favicon.ico or just live_favicon.ico? If the favicon file is in the same root as the .htaccess file, would it still need that / ?

And does it matter SEO-wise if the filename is not just favicon? Are we hurting ourselves by having it named live_ or test_ ?

Do we have to restart Apache after making this change?
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Tip: Keep in mind, what you're doing will work differently than you imagine.

1) The RewriteRule defaults to a 301 permanent redirect.

2) Any previous visitor will always see the 301which will return /graphics/live_favicon.ico forever, no exception... well... till someone manually clears their browser cache.

3) Tip: You're making this seriously complex. Use KISS - Keep it super simple, by doing this.

mv /graphics/live_favicon.ico /favicon.ico

RewriteRule /graphics/live_favicon.ico /favicon\.ico [L]

4) Don't muck about with your test favicon.ico file at all. To test a different favicon.ico file, just direct your browser to the actual URL, as in...

https://foo.com/new-icon-file-name.ico
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

I'm just wondering why you want to delete the graphics folder?

This is the first time I see someone using RewriteRule for favicon, I mean I think this is not common...

Like David suggest at point 4 you can keep the direct link In head part.

You may want to add other icons as well see this tool that can generate all OS version  and platform including mobile.
https://realfavicongenerator.net/

Author

Commented:
#do things different on prod
<IfDefine prod>
RewriteRule ^favicon\.ico$ /graphics/live_favicon.ico [L]
</IfDefine>
<IfDefine !prod>
RewriteRule ^favicon\.ico$ /graphics/test_favicon.ico [L]
</IfDefine>

That has been in our .htaccess file for a long time as far as I know.

We want to remove the graphics folder because there's nothing else in there that we need and we're trying to cleanup so our codebase and file structure isn't a rats nest.

I'd rather not reinvent the wheel here unless absolutely necessary OR beneficial.

So if I choose to forego some of the advice here at my own risk, it sounds like I could just do what Kimputer said, correct? I guess I don't need answer to the questions I posted after his post.
David S.Consultant & Challenge Subduer
Top Expert 2009

Commented:
David Favor, doesn't that only apply for external redirections? We're talking about internal redirections here.

I'm not aware of any current browser versions that still do this, but some browsers (probably IE but I'm not sure) would request favicon.ico directly from a site's root directory.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You can verify exactly what's being returned by visiting the URL using...

curl -I -L https://foo.com/graphics/live_favicon.ico

Open in new window


All major browsers attempt to fetch /favicon.ico unless the HTML of the page over rides this using a meta tag.

Author

Commented:
Kimputer,

I will do what you suggest, basically just removing the /graphics part, correct?

#do things different on prod
<IfDefine prod>
RewriteRule ^favicon\.ico$ /live_favicon.ico [L]
</IfDefine>
<IfDefine !prod>
RewriteRule ^favicon\.ico$ /test_favicon.ico [L]
</IfDefine>

Also, I'm not sure what you mean by:
"Check for the definitive meaning by searching it in the rest of the htaccess file."
Commented:
Correct

"Prod" is not a set standard, meaning it's a variable, set for some custom meaning. The real meaning, is therefore explained somewhere else in the file. Probably it's just to define the URL being the production or test url.

Author

Commented:
Thanks all.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial