Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve favicon.ico from somewhere other than root

ASP.NET Core 2.1.

My favicon is at /images/favicon.ico and cannot be changed. So pages include this:

<link href="/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />

And that works.

But requests directly to example.com/favicon.ico will fail with a 404.

How do I redirect example.com/favicon.ico to example.com/images/favicon.ico?

like image 769
lonix Avatar asked Oct 17 '22 14:10

lonix


1 Answers

In the Configure method of your Startup class, add the following code

RewriteOptions rewriteOptions = new RewriteOptions().AddRedirect("favicon.ico", "images/favicon.ico");

app.UseRewriter(rewriteOptions);

See this page for more information

like image 132
Mathieu VIALES Avatar answered Oct 21 '22 07:10

Mathieu VIALES