how to change favicon

Vote:
 

Hi ,

I have multiple sites. i want to change or apply favicon to indivitual sites.

how can i modify favicon for every site.

#229721
Edited, Oct 22, 2020 5:45
Vote:
 

Hi,

Probably the easiest route would be to simply define the favicon in your layout and allow it to be managed in the CMS per site like this:

<link rel="shortcut icon" href="@Url.ContentUrl(Model.Layout.FaviconRef)" type="image/x-icon" />

This has its limitations though in that you would only get the correct favicon for pages, not for assets or APIs, etc.

For a more comprehensive solution, you'd need to intercept requests for favicon.ico and respond with the appropriate favicon for the site you're currently on. If you're not regularly adding sites without a release, you could do this in config using rewrite rules:

    <rewrite>
      <rules>
        <rule name="Favicon Site 1">
          <match url="^favicon.ico$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^mysite.com$" negate="false" />
          </conditions>
          <action type="Rewrite" url="/favicons/site1.ico" />
        </rule>
        <rule name="Favicon Site 2">
          <match url="^favicon.ico$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^myothersite.com$" negate="false" />
          </conditions>
          <action type="Rewrite" url="/favicons/site2.ico" />
        </rule>
      </rules>
    </rewrite>

If you need a bit more flexibility, you could allow the favicon to be managed in the CMS then intercept the request either through routing or tying into the BeginRequest event and responding with the appropriate favicon as defined in the CMS.

#229726
Oct 22, 2020 7:56
Vote:
 

Hi Sandeep

I would recommend storing the icon reference on the start page, and just render it's URL in the HTML header. This is the simplest way to support different favicons per sites in a multi-site solution.

#229749
Oct 22, 2020 17:55
Vote:
 

Hi Paul,

Thanks for your reply.

am included below code in my web.config file. but its not rewriting my favicon icon.

here am trying to rewrite in my localhost in my system.

<system.webServer>
<rewrite>
<rules>
<rule name="Favicon Site 1">
<match url="^favicon.ico$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^localhost$" negate="false" />
</conditions>
<action type="Rewrite" url="/Gi Group_Favicon.ico" />
</rule>
</rules>
</rewrite>

#229889
Oct 26, 2020 7:09
Vote:
 

The suggestions from Stefan & Paul are great and I would go with those solutions in a heartbeat.

If you want to keep the same url you could potentially add a custom route for the "/favicon.ico" url and use a controller with ContentReference.StartPage to know the website that is being requested and return the right favicon based on your business logic - the favicon can be from the cms, separate database, xml config, etc.

You can reuse some of the code available in this article: https://world.episerver.com/blogs/giuliano-dore/dates/2020/10/how-to-create-a-simple-robots-txt-handler-for-a-multi-site-episerver-project/

#229902
Oct 26, 2020 14:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.