Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Shortening URLs in AEM | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Shortening URLs in AEM by JUAN AYALA

Abstract

Let’s face it, AEM URLs are ugly! Shortening them has been a requirement in every single AEM Sites implementation I have worked on.

Why do clients want shorter, optimized URLs? First of all, less complicated URLs are more user friendly. They are easy for site visitors to type, clearer to read so a visitor is confident they are going to a relevant page, and less prone to user error when copy/pasting or retyping. From an SEO perspective, Google and other search engines can crawl a site more easily when the site structure (subfolders are used well) is clear and the URLs are easy to read without a ton of unnecessary symbols or parameters.

Here is a typical AEM URL:
http://www.mysite.com/content/mysite/en/mysection/mypage.html

Instead of that, we would shorten the URL to:
http://www.mysite.com/en/mysection/mypage.html

Or assume en is the default:
http://www.mysite.com/mysection/mypage.html

Or remove the extension:
http://www.mysite.com/mysection/mypage/

Unfortunately, there is no single configuration or feature that shortens URLs. Instead, several things come together. Let's cover some terms first.

Outgoing URLs (aka mapping)
Outgoing URLs are the ones getting rendered out and sent to the browser. They can exist in thecustomer

HTML markup as anchor hrefs, form actions, or image sources. Before the AEM publisher sends back the requested page it will need to call ResourceResolver.map(String resourcePath) on all of the long URLs to map them to their short-form.

Incoming URLs (aka resolving)
When the user clicks on one of those short URLs, the browser will start a request that goes back to the dispatcher first. Then, it gets proxied back to the AEM publisher. The publisher will need to call ResourceResolver.resolve(String absPath) to resolve that URL back to its long-form.

Project Archetype
Now that we know the difference between mapping and resolving, let's take a look at the AEM project archetype. I love the project archetype. It is an excellent source of best practice examples that is constantly updated. Over the past few years, the configurations to handle short URLs have been added. I will point them out to you.

Read Full Blog

Shortening URLs in AEM

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
1 Reply

Avatar

Level 2

Hi @kautuk_sahni ,

I am able to remove the extension ".html" but the internal remapping is not working. Hence, the pages are breaking without  ".html".

It will be great if you can elaborate part : Challenge #2 - Extensionless URLs 

from the Blog https://blog.3sharecorp.com/shortening-urls-in-aem

Thanks!