Blogs > Handelling Vanity URLs in AEM
AEM Sites
Handelling Vanity URLs in AEM
| July 9, 2023Lets begin today's learning regarding vanity urls and their handelling in AEM.
Introduction
Vanity URLs are nothing but friendly URLs. Suppose we have a URL:localhost/content/abc/def/ghi/organization/team.html which is not really eye catching to the users so AEM authors are provided the previllege to transform this URL into a more user friendly URL such as localhost:4502/organization/team.html which is indeed a vanity url of the provided one.
Adding Vanity URLs via Page Properties
In order to do this, AEM Authors should open the page properties of the page and set up the friendly.
Go to Basic tab and find vanity path as a multifield to add the required vanity url and select save and close.
There in you also find a Redirect checkbox, if checked, the vanity url generates a status code of 302 along with initiator as other and reaches the parent url through internal redirect.
The vanity URL on the other hand provides a status code of 200 with initiator as the vanity url itself
Dispatcher Configuration of Vanity URLs
Everytime an author adds a vanity url, its entry needs to be made at the dispatcher level and this becomes tedious so, in AEM dispatcher has an auto allow feature listed in vanity tree.
All the map entries for vanity urls are available in localhost:4502/system/console/jcrresolver stating external redirect with status code 302.
In order to exercise auto-filter mechanism of dispatcher content/software distribution package needs to be downloaded (a feature of AEM Cloud as a Service) and configured in the dispatcher itself.
In dispatcher, /vhost, we specify the rules for vanity_urls. Also we can specify which file should store vanity urls and after how many seconds the file must get refreshed.
/vanity_urls{
/url "/libs/granite/dispatcher/content/vanityUrls.html"
/file "/temp/vanity-urls"
/delay "400"
}
Here /libs/content/dispatcher/content/vanityUrls.html is a page that displays all the vanity urls available in AEM.
/temp/vanity-urls is file that stores all the vanity urls
/delay 400 is the time period till which the /temp/vanity-urls file will not get refreshed if the time difference between current moment and file's last modification is less than that of /delay.
A refreshed request can be explicitly trigerred by just requesting a non-existing url to ensure /delay elapse.
For example : localhost/non-existing/page.html
It is recommended to use rewrite rules instead of default mechanism to ensure namespace resolutions, higherlevel logic implementation and increased performance.
RewriteRule ^/home /content/abc/def/ghi/home.html [PT,L,NC]
L (i.e last flag) is used to increase the performance as it skips the unnecessary rules without generating a proxy request. PT (i.e pass through flag) looks for a vanity url starting with provided initals and then fetches the complete path from the renderer. NC (i.e no case sensitivity) ignores casings.
I hope you find this blog informative and helpful and if so please do like.