Automatically rewrite links to remove /content/ path? | Community
Skip to main content
January 7, 2022
Solved

Automatically rewrite links to remove /content/ path?

  • January 7, 2022
  • 2 replies
  • 1591 views

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.
Best answer by ibishika

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

ibishika
ibishikaAccepted solution
January 7, 2022

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.

RajaShankar
Community Advisor
Community Advisor
January 8, 2022

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