htaccess references favicon file, move the file to root?

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.
LVL 1
BobbyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerIT ManagerCommented:
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.
BobbyAuthor 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 FavorLinux/LXD/WordPress/Hosting SavantCommented:
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
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

lenamtlCommented:
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/
BobbyAuthor 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 SubduerCommented:
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 FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
BobbyAuthor 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."
KimputerIT ManagerCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BobbyAuthor Commented:
Thanks all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.