April 26, 2020
Estimated Post Reading Time ~

URL Shortening in AEM

Content pages in AEM start with path /content/. It is best practice to hide /content/site in the URL.
http://localhost:4502/content/site/en/page.html

Below configs show how to achieve URL shortening on both AEM server and dispatcher.

Configs on AEM Server:

· There are many ways to configure the rewrites on publish server. e.g. Resource Resolver, Vanity URLs, Sling mapping.
· Configuring the Apache Sling Resource Resolver Factory is one of the ways to configure rewrites. This service needs to be configured on the publish server so that if someone hits the publish server directly; we see the correct rules applied there.
Make sure that the publish server has the below configuration applied


Configs on Dispatcher:

Open dispatcher.conf file and update DispatcherUseProcessedURL value to 1

DispatcherConfig conf/dispatcher.any
DispatcherLog logs/dispatcher.log
DispatcherLogLevel 3
DispatcherNoServerHeader 0
DispatcherDeclineRoot 0
DispatcherUseProcessedURL 1
DispatcherPassError 0

· Open httpd.conf, uncomment below line
LoadModule rewrite_module modules/mod_rewrite.so

· Add below rewrite rules in dispatcher.conf file
RewriteEngine on

# remove any trailing slash, if it's there.
RewriteRule ^(.+)/$ $1

#Shorten the URL
RewriteRule ^/content/site/(.*).html$ $1.html [R,L]

#Map the root folder to the home page
RewriteRule ^/?$ en/page.html [R,L]

# Ignore requests to "known" AEM root paths, and prefix all others with the proper AEM prefix
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
#RewriteRule ^/(.*)$ /content/site/$1 [PT,L]


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.