Pages

Wednesday, April 18, 2018

How to implement extension-less URL's in Adobe Experience Manager(AEM)

How to implement extension-less URL's in Adobe Experience Manager(AEM)

As per the SEO best practices it is better to define extension less URL's to boost the ranking, AEM require the extension to understand and serve incoming request.

This post explains the approach to achieve the extension less URL in Adobe Experience Manager(AEM)

There are two steps

- Rule Configuration Dispatcher
       Remove .html extension from incoming URL with /
Append the .html while invoking the publisher for the URL's ending with /

- AEM etc/map configuration
      Reverse mapping to rewrite the html URL in the pages to extension less
      Forward mapping to map the incoming request to resource

This is tested in AEM 6.2 version

Apache configurations:


#Handle the landing page
RewriteRule ^/$ /en/ [R=301,L]
#Mask the /content/geometrixx-outdoors path
RewriteRule ^/content/geometrixx-outdoors/(.*)(\.html)?$ /$1 [NE,L,R=301]

#Replace the .html with /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^/(.*).html$ /$1/ [R=301,L,QSA]

#Append the .html for those URL's ending with / before sending to publisher
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^/(.*)/$ /$1.html [PT,L,QSA]

Publisher etc/map configurations:


Create a node localhost.8080(replace with required DNS and port) of type sling:Mapping under /etc/map/http or /etc/map/https based on the protocol used

Add the following property

sling:internalRedirect[] - /content/geometrixx-outdoors

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Mapping"
    sling:internalRedirect="[/content/geometrixx-outdoors]">
    <redirect/>
    <reverse/>
</jcr:root>

AEM-extension-less-URL



Create  a node "redirect" of type sling:Mapping under localhost.8080 - map the incoming request to AEM resource path

Add the below properties

sling:internalRedirect[] - /content/geometrixx-outdoors/$1 , /$1
sling:match - (.+)$

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Mapping"
    sling:internalRedirect="[/content/geometrixx-outdoors/$1,/$1]"
    sling:match="(.+)$"/>

AEM-extension-less-URL


This will help to perform the forward mapping of URL to the resource by sling, resourceResolver.resolve() API can be used if programmatic mapping is required

Create a node reverse of type sling:Mapping under localhost.8080 - Reverse mapping , map the content path to shortened and extension less URL

sling:internalRedirect[] - /content/geometrixx-outdoors/(.*).html
sling:match - $1/

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Mapping"
    sling:internalRedirect="[/content/geometrixx-outdoors/(.*).html]"
    sling:match="$1/"/>

AEM-extension-less-URL


This will help the rewriter to perform the Reverse mapping of the html links in the pages to shortened and extension less URL's.
The output rewriter pipeline automatically rewrite all the html links in the pages to shortened and extension less URL's based on the above configuration, resourceResolver.map() API can be used if programmatic mapping is required

Now the browser displays the extension less URL for the html page request and also the html links inside the page is converted to extension less

AEM-extension-less-URL


The extensions from the page links can be striped off by enabling the "Strip HTML Extension" configuration in "Day CQ Link Checker Transformer" also but

 - This configuration is not site specific and applied for all the sites hosted
 - In AEM 6.3 i was facing too many redirect issue by enabling this configurations along with above mentioned Apache rules but the same is working fine in AEM 6.2
- This will not append the / at the end of rewritten URLs

Strip-HTML-Extension

Strip-HTML-Extension







No comments:

Post a Comment