Developer System Administrator

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

 

<?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>
        <name>Replace / to .html</name>
        <from>^/cms/render/live/(\w{2})/sites/digitall(.*)/$</from>
        <to>/cms/render/live/$1/sites/digitall$2.html</to>
    </rule>
    
    <rule>
        <name>Replace / to /home</name>
        <condition type="attribute" name="internalCustomRedirect" operator="notequal">^true$</condition>
        <from>^/cms/render/live/(\w{2})/sites/digitall(?!/contents)(.*)\.html$</from>
        <set type="request" name="internalCustomRedirect">true</set>
        <to>/cms/render/live/$1/sites/digitall/home$2.html</to>
    </rule>

    <outbound-rule>
        <name>Remove /home</name>
        <from>^/cms/render/live/(\w{2})/sites/digitall/home(.*)\.html(.*)$</from>
        <to>/cms/render/live/$1/sites/digitall$2/$3</to>
    </outbound-rule>

    <outbound-rule>
        <name>Remove .html</name>
        <from>^/cms/render/live/(\w{2})/sites/digitall(.*?)\.html(.*)$</from>
        <to>/cms/render/live/$1/sites/digitall$2/$3</to>
    </outbound-rule>
 
</urlrewrite>