Forum Moderators: phranque

Message Too Old, No Replies

any folder - one file

redirect requests for favicon.ico

         

smallcompany

11:19 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There was a discussion about requests for favicon.ico in subdirectories.

I'm tired of 404s, and I don't want to put favicon in each subdirectory.

So, I wonder about redirect that would send a request for favicon.ico in any sub-folder (except root) to the existing one in root.

I searched the web and WW but could not find the solution (or could not recognize it).

I thought about it and figured this:

RewriteRule ^/(.*)/favicon\.ico$ http://www.example.com/favicon.ico [R=301,L]

Would this above be OK for a one level subfolder?

How about sub-sub folders and so on? Is there a way to say "subfolder any level", and then to specify a file?

Thanks

P.S.
Just found this:

RewriteRule (.+)/favicon\.ico$ /favicon.ico [L,R=301]

?

jdMorgan

11:31 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No redirect is needed, and redirecting would cause a second HTTP request, slowing down both your visitors' browsers and your server. Just internally rewrite all of the URL requests to the same favicon file:

RewriteRule ^([^/]*/)+favicon\.ico$ /favicon.ico [L]

That will take care of all favicon requests in all 'subdirectories'.

Jim

smallcompany

12:40 am on Nov 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks very much!

This created a question in my mind about "what's the difference between":

RewriteRule ^/old\.html$ /new.html [R=301,L]

and

RewriteRule ^/old\.html$ http://www.example.com/new.html [R=301,L]

I do the second one as I remember reading how that ensures the "right" redirect with no problems.

Is the second one unnecessary "outside" request?

Thanks

g1smd

1:48 am on Nov 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The second one ensures the user makes a new request for the correct protocol, sub-domain and domain irrespective of what the URL of the page containing the link was.

That is, the other rule redirects www to www and non-www to non-www. It redirects http to http and https to https. That is likely a BAD thing.

.

However, in this case you do NOT want a redirect, you want a rewrite. Look closely at jd's example code. It does not contain the [R] flag, nor a domain name. The code is for a rewrite, not for a redirect.

smallcompany

3:50 am on Nov 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



However, in this case you do NOT want a redirect, you want a rewrite. Look closely at jd's example code. It does not contain the [R] flag, nor a domain name. The code is for a rewrite, not for a redirect.

Yes, I got the message about particular rewrite - rather then a redirect, but then got the inspiration to rethink the way how I do redirects.

So the thorough way is good for redirects like old pages, non-existing pages, etc... anything that requires 301.

Thanks