Let’s say I want to route the /favicon.ico request to /assets/icons/favicon.ico in order to keep a tidy root folder. What is the best way I would go about doing that?
I cannot see anything wrong in your code, and indeed when trying I can replicate this issue. The first route example you posted works perfectly fine with patterns '/favicon' or '/favicon.jpg', but not with '/favicon.ico' (the / prefix is optional, as far as I know, but the outcome is the same).
In a similar situation a user once had success with putting the route into a plugin rather than into config.php, but at least for me that does not solve the problem at hand; I tried with a plugin and get the exact same outcome.
It almost feels like the router chokes on the .ico being part of the route (as I get a 404 error but no error page, as I do for any other URL that does not exist). Or the server configuration deals with .ico URLs somehow differently – I do not get any error messages in my server logs, though, and there are no .ico-specific rules in my server setup files either (Nginx/Linux).
Mysterious!
PS. You could of course bypass this specific problem by adding a rewrite rule to your .htaccess instead (if you’re on Apache).
That was really helpful, in many ways! I still don’t have a solution for my local environment (Laravel Valet which has Nginx) but I uploaded the first solution to my server and it works!
So your guess is probably correct, something about Nginx and .ico makes it go haywire. Now, I would like to see what’s wrong exactly, because inconsistencies between dev and prod are a cause for concern, but at least it works.
Now I’m not exactly an expert on Nginx configurations, but that seems to be the culprit?! If I read that line correctly, the request for the /favicon.ico never even reaches PHP, or Kirby, for that matter.