Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

Implementing URL Shortening in AEM 6.5 Without Relying on Dispatcher Rules

Avatar

Level 1

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.)?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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:

Use /etc/map for Path Mapping

You 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:

  1. Create a node under /etc/map.publish/http (or /etc/map depending on your setup).

  2. 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.

Custom Sling Servlet or Filter

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.

Vanity URLs

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!


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

4 Replies

Avatar

Community Advisor

@NehaBa4 

 

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.


Aanchal Sikka

Avatar

Community Advisor

@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.

Avatar

Community Advisor and Adobe Champion

Avatar

Correct answer by
Community Advisor

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:

Use /etc/map for Path Mapping

You 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:

  1. Create a node under /etc/map.publish/http (or /etc/map depending on your setup).

  2. 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.

Custom Sling Servlet or Filter

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.

Vanity URLs

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!


Santosh Sai

AEM BlogsLinkedIn