How to use internal redirects in AEM? (Part 2)

Reading Time: 2 minutes

Specifying the domain

As we saw earlier, in the first part of this post series, we can specify the matching URL of our mappings with the sling:match attribute e.g. “”. We can also specify the domain outside the sling:match attribute by using it as the node’s name.


As we can see in the image, now we just put “news” in the matches attribute and omit the domain. Sling will take the node’s name add use it to add the rest of the URL. So the mapping in the example will look for the URL matching the following: “” and make an internal redirect to “”.

But, what if you have several rules that you want to apply for the same domain?. Well, in that case, you can create a sling:Folder type node with the domain as the name, and create the mapping nodes inside. it would look like:


Now you will be able to group mapping for different domains.

Using regular expressions

Let’s suppose we are asked to hide the “content” segment on the URL as well as the “.html” extension on all the pages under “news”. One option is to create a mapping for each one of the pages, but as the number of pages grow, maintainability will start to be an issue.

The best way to handle that situation is to use regular expressions. So, the solution is to use a regular expression in the sling:match with a capture group like this: “news/(.+)” so we can get the name of the page. Then, in the sling:InternalRedirect attribute we need to interpolate the page name by getting the content of the capture group as follows: “/content/news/$1.html”.


One difference between using and not using regular expressions in the mappings is that they are added under the “Resolver Map Entries” section in the system console instead of the “Mapping Map Entries” section and I will look like:


For more information about this topic, check the Apache Sling documentation.

That’s it for now, thanks for reading!

Adobe Experience Manager
Having a glimpse at the WCM Search API and the Query Builder (AEM)
Adobe Experience Manager
A quick look to Services in AEM
Adobe Experience Manager
A quick look into the JCR Search API (AEM)
Copy link
Powered by Social Snap