How to use internal redirects in AEM?: Part 2

Reading Time: 2 minutes

When migrating a Ruby on Rails-based Application to Adobe Experience Manager we needed to use internal redirects. In this blog post, we are going to show you how to specify the domain and use regular expressions. It is very easy. Keep reading!

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.


If we take a look at the image above, we can see that 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!

You May Also Like
Read More

Responsive layouting in AEM

Reading Time: 5 minutes Responsive layouting allows you to add components inside a responsive grid which give you the ability to: Change the…