views:

571

answers:

4

How do I redirect all requests for favicon.ico in root directory or any subdirectory to /images/favicon.ico

A: 

ModRewrite On

RewriteRule ^(.*)favicon.ico /images/favicon.ico

Sejanus
the ^ in front is very important
Marcos Placona
This is giving me an internal server error.Is it beacause (.*)favicon.ico also matches /images/favicon.ico so it becomes a loop
Tim
Checked error log and it states "Request exceeded the limit of 10 internal redirects due to probable configuration error" so looks like it is indeed redirecting to itself. How do I get around that?
Tim
Right I skipped [L] flag. Try as per Gumbo's reply.
Sejanus
I think I need to use this with a RewriteCond to say if request URI not /images/favicon.ico not sure the correct syntax though
Tim
A: 

This quick rewrite should do the trick:

RewriteRule ^(.*)favicon.ico /images/favicon.ico

Marcos Placona
+3  A: 

Try this rule:

RewriteEngine on
RewriteRule ^favicon\.ico$ /images/favicon.ico [L]

Edit    And for favicon.ico with arbitrary path segment depth:

RewriteCond $0 !=images/favicon.ico
RewriteRule ^([^/]+/)*favicon\.ico$ /images/favicon.ico [L]
Gumbo
This works for /favicon.ico but not for /folder/favicon.icoSome browsers are requesting favicon.ico in local folder even though it's specified as /images/favicon.ico so I wanted to redirect the currently failing requests to the correct location
Tim
A: 

I know the question is tagged .htaccessbut, why not use a symlink?

ln -s images/favicon.ico favicon.ico
gregseth
Tim