Hello,
In our current project setup, we are handling URL shortening through custom rules configured at the dispatcher level.
Example of current behavior: When a user accesses: www.domain.com/us/en/testpage.html
it internally maps to: /content/project/us/en/home/testpage
We have now received a new requirement where we need to achieve this shortening behavior without using dispatcher rewrites.
The goal is to allow URLs like:
To be resolved directly to:
/content/project/us/en/home/testpage
Has anyone implemented this purely within AEM (e.g., via Sling Mappings, ResourceResolvers, filters, etc.)?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @NehaBa4,
Since you are trying to handle URL shortening without relying on dispatcher rewrites, one common and effective way is to leverage AEM’s Sling Resource Resolver mappings (/etc/map
) along with a custom redirect logic if needed.
Here are few ways you can consider doing:
/etc/map
for Path MappingYou can define resource resolver mappings to rewrite incoming URLs to your internal content paths.
For example:
/etc/map.publish/http/www.domain.com.us/en/testpage.html -> /content/project/us/en/home/testpage
To implement this:
Create a node under /etc/map.publish/http
(or /etc/map
depending on your setup).
Use a structure like this:/etc/map.publish/http/www.domain.com
(sling:Mapping node)
with properties like:
sling:internalRedirect
= /content/project/us/en/home
sling:match
= /us/en/testpage.html
This way, AEM can resolve shortened URLs internally without dispatcher involvement.
If your URL structure is dynamic and complex (for example, /testpage.html
should map based on the current locale or user session), you might consider writing a custom Sling Servlet or Filter that intercepts incoming requests and internally forwards or resolves them.
This would allow you to programmatically determine the correct path based on business rules.
Another option is to use vanity URLs configured at the page level. Just be cautious about performance and uniqueness if you're planning to use it at scale.
Hope this helps!
I have used Sling Mappings for URL Shortening. However, using Sling Mappings along with Dispatcher rewrites can provide better results.
https://meticulous.digital/blog/f/aem-url-shortening-sling-mappings-vs-dispatcher-rewrites
For Incoming requests, Dispatcher can expand domain specific URLs and utilize the dispatcher cache for serving requests.
For Outgoing URLs, Sling Mappings can help shorten the links in content.
@NehaBa4 : Is there a specific reason for not using dispatcher redirects for this?
With dispatcher redirect rule it is quite simple to redirect for your AEM site structure -
something like this - RewriteRule ^/(.*)$ /content/project/$1 [PT,L]
where $1 will be your incoming url - "us/en/home/testpage"
If you can challenge the reason for not having dispatcher redirect, it is probably best to have it with dispatcher rule.
thanks.
Views
Replies
Total Likes
Hi @NehaBa4,
this article should explain it: https://meticulous.digital/blog/f/aem-url-shortening-sling-mappings-vs-dispatcher-rewrites
Good luck,
Daniel
Views
Replies
Total Likes
Hi @NehaBa4,
Since you are trying to handle URL shortening without relying on dispatcher rewrites, one common and effective way is to leverage AEM’s Sling Resource Resolver mappings (/etc/map
) along with a custom redirect logic if needed.
Here are few ways you can consider doing:
/etc/map
for Path MappingYou can define resource resolver mappings to rewrite incoming URLs to your internal content paths.
For example:
/etc/map.publish/http/www.domain.com.us/en/testpage.html -> /content/project/us/en/home/testpage
To implement this:
Create a node under /etc/map.publish/http
(or /etc/map
depending on your setup).
Use a structure like this:/etc/map.publish/http/www.domain.com
(sling:Mapping node)
with properties like:
sling:internalRedirect
= /content/project/us/en/home
sling:match
= /us/en/testpage.html
This way, AEM can resolve shortened URLs internally without dispatcher involvement.
If your URL structure is dynamic and complex (for example, /testpage.html
should map based on the current locale or user session), you might consider writing a custom Sling Servlet or Filter that intercepts incoming requests and internally forwards or resolves them.
This would allow you to programmatically determine the correct path based on business rules.
Another option is to use vanity URLs configured at the page level. Just be cautious about performance and uniqueness if you're planning to use it at scale.
Hope this helps!
Views
Likes
Replies
Views
Likes
Replies