Forum Moderators: phranque
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]
?
RewriteRule ^([^/]*/)+favicon\.ico$ /favicon.ico [L]
Jim
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
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.
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