Developer System Administrator Jahia 8

Remove home and .html suffix from URLs

Question

How to remove the .html suffix and home from the URLs of my website?

Answer

It can be achieved by using the Tuckey url rewriting framework even if it's not something we advise as it can have unforeseen effects.

If your site key is digitall, you can put the following content in your template module:

  • in the file ./src/main/resources/META-INF/urlrewrite-digitall.xml
<urlrewrite>
    <rule>
        <name>Replace / to .html</name>
        <from>^/cms/render/live/(\w{2})/sites/(digitall)(.*)/$</from>
        <to>/cms/render/live/$1/sites/$2/home$3.html</to>
    </rule>
    
    <outbound-rule>
        <name>Remove .html</name>
        <from>^/cms/render/live/(\w{2})/sites/(digitall)/home(.*?)\.html$</from>
        <to>/cms/render/live/$1/sites/$2$3/</to>
    </outbound-rule>
</urlrewrite>
  • in the file ./src/main/resources/META-INF/seo-urlrewrite-digitall.xml
<urlrewrite>
    <rule>
        <name>Add the /home.html</name>
        <condition type="attribute" name="jahiaSkipInboundSeoRules" operator="notequal">^true$</condition>
        <condition type="attribute" name="jahiaSiteKeyForCurrentServerName" operator="notequal">^$</condition>
        <from>^/$</from>
        <to last="true">/home.html</to>
    </rule>
    
    <outbound-rule>
        <name>Remove the /home.html</name>
        <from>^(/[\p{Alnum}-_]*)?/home.html$</from>
        <to>$1/</to>
    </outbound-rule>
</urlrewrite>