Automatically rewrite links to remove /content/ path? | Community
Skip to main content
Level 2
Jan 7, 2022 6:07 PM UTC
Solved

Automatically rewrite links to remove /content/ path?

I have a website where the site structure is /content/mysite/us/en/page.html.

 

I have the following sling mapping set up so the site can be served without /content/ in the path at https://example.com/mysite/us/en/page.html:

 

<?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" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:mixinTypes="[cq:ReplicationStatus,sling:MappingSpec]" jcr:primaryType="nt:folder" sling:internalRedirect="[/content/mysite/$1/$2/$3]" sling:match="mysite/([a-z]{2})/([a-z]{2})/(.*)"/>

 

The problem is, when I view the site without the /content/ path in the URL, all the links on the page still contain /content/ in them. How do I implement the feature so that /content/ is automatically removed from all link element attributes when the URL does not contain /content/ in it?

 

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ibishika
ibishikaAccepted solution
Level 4
Jan 7, 2022 8:38 PM UTC

You need to write a service to process the links based on whatever the criteria you want.

Now in each of the component/places where you use any link, call that service to process the link and return the updated link that you get from the service.

2 replies

RajaShankar
New Participant
Jan 8, 2022 1:37 AM UTC

Hi @nydel09  You need to implement sling reverse mapping for this that will resolve the issue.

Please refer this article for reverse sling mapping to remove /content reference inside the rendered web pages

https://www.albinsblog.com/2020/07/configure-sling-mapping-for-resource-resolution-in-adobe-experience-manager.html

 

Regards,

Rajashankar.R

Translate
ibishika
ibishikaAccepted solution
Level 4
Jan 7, 2022 8:38 PM UTC

You need to write a service to process the links based on whatever the criteria you want.

Now in each of the component/places where you use any link, call that service to process the link and return the updated link that you get from the service.

Translate