Written by The Jahia Team
 
Developers
   Estimated reading time:

Here are different ways to use your custom favicon.ico

Answer

By default, Jahia uses a custom favicon.ico file. This file in tomcat/webapps/ROOT/favicon.ico and is used in your browser when opening any file.

Here are different ways to use a custom favicon.

Change favicon for HTML content (page served by Jahia)

For HTML content, you can change the path to the icon by setting this kind of instruction in the HEAD part of your code: 

<link rel="icon" href="/path/to/your/custom/favicon.ico" />

This instruction can be done directly in your template set.

This instruction is limited to HTML pages, meaning that if you open another type of content, such as a PDF or an image, then the favicon displayed in your browser tab will be the default one. 

Change the default favicon

If you want to change the default favicon, then you can replace the default file tomcat/webapps/ROOT/favicon.ico with your custom favicon. 
If you use a Jahia cluster, then you will need to do it on all of your nodes.

As a result, all of your web projects will now use your custom favicon.

Override the default favicon for a specific web project

If you want to change the default favicon only for a site, then you can do it using a rewrite rule. This rule will be part of a module (or a template set) and will be enabled only on a specific web project (site)

In the following module example, we will add a new file src/main/resources/META-INF/urlrewrite-favicon.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
    <rule>
        <from>^/favicon.ico$</from>
        <to last="true">/modules/test-favicon/img/favicon.ico</to>
    </rule>
</urlrewrite>


Check the full module code at https://github.com/pvollenweider/test-favicon

The idea is that if this module is enabled on your site, then the rule will be executed, and the URL to /favicon.ico will be redirected to the embedded file /modules/test-favicon/img/favicon.ico

Related links