Tuesday, 30 September 2025

Mastering URL Shortening in AEM: Vanity URLs and Beyond

Quote of the Day

" Train your mind to see the good in every situation  "

 What is URL shortening (or shorthand URL)?

A URL shortening (or shorthand URL) is a way to make a long, complicated web address shorter and easier to share. 

Instead of sharing a long URL like:

https://www.colibra.com/content/weretail/us/en/products/womens/shoes.html

We can create a short, friendly URL like:

https://www.colibra.com/shoes

We have three ways to do URL shortening/create shorthand URLs.
3.etc Mapping

Here, we discussed how to implement URL shortening in AEM using Vanity URLs and how AEM handles this internally.

How we can add AEM vanity Url for a particular page



Step 1: Navigate to this URL and download vanity URL’s components package.


Step 2: Accept EULA terms and conditions and press download button highlighted red in color.



Step 3: Upload vanityurls-components package and install on publish instance:




 Step 4: To add a vanity URL for a specific field available in the page properties.

Go to the page and open its properties.
 

Step 5: Here, the Vanity URL property is a multi-field, which means you can apply multiple vanity URLs for this page.


Step 6: These vanity URLs are mapped as Sling mappings.
    

step 7: after that Save&Close.



Note:
  • The Vanity URL is based on the page, not the domain.
  • Vanity URLs work on both Author and Publish instances.
Step 8: Now access this page.





Step 9: If we want to publish this page, we must first replicate it.


Step 10: Page is accesible using Vanity Url on Publish.


⚙️ How It Works Internally

1.Vanity Property in JCR Node
  • In the JCR repository, when a content author sets a Vanity URL for a page, AEM stores it as a property inside the page’s jcr:content node:
  • For example,
    /content/wknd/us/en/author-info/jcr:content.
  • sling:vanityPath = "/author-info"




  1. AEM provides an internal resource at:

  • /libs/granite/dispatcher/content/vanityUrls
  • This path is part of AEM’s Granite UI framework and is responsible for exposing vanity URL mappings.


  2. sling:resourceType Mapping
  • Node, sling:resourceType = granite/dispatcher/components/vanityUrls
  • This means that when the resource is requested, AEM uses the component located at: /libs/granite/dispatcher/components/vanityUrl to render the response.
 

 3. Accessing in Browser
  • When you open this path in a browser (e.g., http://localhost:4502/libs/granite/dispatcher/content/vanityUrls.html), AEM dynamically generates response.
  • This response contains all the registered vanity URL mappings across the repository (collected from sling:vanityPath properties).

🔎 How AEM Compares and Traverses Vanity URLs Internally

1. Saving the Vanity URL

  • In the page node (/content/wknd/us/en/author-info/jcr:content), AEM adds a property:

sling:vanityPath = "/author-info"

At this point, if we check the /vanityUrls.html response, we’ll see our vanity mapping, which confirms it’s saved.

  • When  hit http://localhost:4502/author-info

sling checks its vanity path mappings.

If a match is found → it traverses the mapping and internally redirects to the actual page path (/content/wknd/us/en/author-info).


On the Dispatcher / Web Server, sometimes the page cannot be accessed using the configured Vanity URL.

Let’s see how we can resolve such issues:


Step 11: To allow Vanity URLs on Dispatcher

We need to add the /vanity_urls section inside the dispatcher.any file. This section allows the dispatcher to resolve Vanity URLs. Here, we have to define three properties:

  • /url → This property points to the service that returns all the available Vanity URLs configured in AEM.
  • /file → Dispatcher stores these Vanity URL mappings in the specified file. This allows the dispatcher to frequently check and resolve Vanity URLs without calling AEM every time.
  • /delay → This defines the time interval (in seconds) between consecutive calls that the dispatcher makes to AEM to refresh the Vanity URL list.


 Advantages of Vanity URLs
  • Easy to remember – Short and clean links are more user-friendly.

  • Author controlled – Content authors can manage URLs directly from page properties.

  • Marketing friendly – Perfect for campaigns, landing pages, and promotional content.

Disadvantages of Vanity URLs

  • Performance impact – Vanity URLs are resolved at runtime. If you configure thousands of vanity URLs or sling mappings, it can become an expensive operation in terms of resources.

  • Dispatcher setup required – Vanity URLs must be enabled and properly configured in the dispatcher.

  • Not scalable for bulk usage – If many URLs need to be shortened, other approaches like Apache rewrite rules or URL mapping may perform better.

     Thanks !!



No comments:

Post a Comment

Extending AEM Components Using sling:resourceSuperType — Powered by Sling Resource Merger

Quote's of the day "You never fail until you stop trying" What is Sling Resource Merger ?   Sling Resource Merger is the hidd...