Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

AEM 6.4 Resource Resolver Mapping home page to root

Avatar

Level 2

This seems like a fairly common use case but we have a client that is experiencing some issues with url rewriting / shortening.

The gist is, the client would like to have all links on the site that link to the home page '/content/client-site/en/home' to map to root '/'. Also note that all content lives under this home page.

Using the resource resolver we have mappings to shorten the urls on the publish instances:

/content/client-site/en/home/(.*):/$1

/content/client-site/en/home:/

We have a few Apache rewrites on the dispatcher side to handle content shortening and redirection properly.

What the client is experiencing is when they create a link on a page back to the homepage and use a relative path in author; once published the url is mapped to '/' but a '.html' extension is being added. In short the url to the home page ends up looking like '/.html' instead of '/'.

6 Replies

Avatar

Community Advisor

To handle the case, you'll have to create 2 cases here:
1. Specifically for root page
2. For all pages under home pages hierarchy.

E.g.


localhost_4503

<?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/client-site/en/home.html]"

    sling:match="www-release.newrelic.com/$"/>

localhost.4503

<?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="[/$1,/content/client-site/en/home/$1]"

    sling:match="(.+)$"/>

Using the above mentioned sling mapping cases, the root page will be delivered for domain name and for below hierarchy, the anothe rule will come in picture

Avatar

Level 2

So, I have doubts that this suggestion will rewrite the link on the page accordingly. The issue is when there is a link on any page that redirects to the home page, when you hover over that link it appears as '/.html'. It's almost as if something is forcing extensions on all links.

I added your suggestion(s) to my local publish instance to validate, when examining the links on the page they still pointed to full path of '/content/client-site/en/home' and had not been shortened as expected.

Avatar

Community Advisor

Kindly make sure that in the configuration "Day CQ Link Checker Transformer" , Strip HTML Extension option is checked. If not, it by default adds the .html extension to url. If you'll check, it'll start stripping off .html extension from url.

And, for, url shortening not working, kindly share the mapping or please share the mapping package.

Best regards,

Himanshu Singhal

Avatar

Level 1

Thx for your suggestions Himanshu. Unfortunately, stripping html extensions from page urls is not really a solution as that would apply to all urls on the site. Which is not what the client wants. All valid urls that point to a page should have the '.html' extension; however links to the root of the site should not have the extension added.

The url shortening is working perfectly. The only issue is when mapping a page to the root the resulting url ends up being '/.html' For our custom components such as CTAs, header/footer logos with links; we have a implemented custom code to handle these situations and ensure if the mapped url does not map to a page and/or maps to the root, the extension is not added.

However for OOTB components, such as the RTE, AEM doesn't really do any type of intelligent checking of the link to prevent the extension from being added to an empty string. Which is ultimately what we need.

Avatar

Community Advisor

Hi,

I understand your point and for that you can implement custom LinkTransformer and add the condition the way you wants to handle links re-writing.
Doesn't matter if the component is custom or OOTB, all the link rewrite control will goes in custom LinkTransformer (if implemented) and there you handle it.


Creating a Link Rewriter Service for Adobe Experience Manager 6.3

Using LinkTransformer - How is it triggered?

Avatar

Level 2

You can try something like this

One sling map rule for your Home/root page and one for your child pages

Home Page

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"

    jcr:primaryType="sling:Mapping"

    sling:internalRedirect="/content/client-site/en/home.html"

    sling:match="www.myDomain.com/"/>

Child Pages

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"

    jcr:primaryType="sling:Mapping"

    sling:internalRedirect="[/content/client-site/en/home/(.*)]"

    sling:match="www.myDomain.com/$1"/>