January 5, 2021
Estimated Post Reading Time ~

Vanity URLs In AEM – Part 2

In our previous blog, we have seen how to create Vanity URLs in AEM. But, just by creating vanity URLs, end-users will not be able to access the page using the vanity URL as a request from the end-user first hits dispatcher. And the dispatcher doesn’t have the list of vanity URLs. So, the dispatcher has to work continuously with AEM to get the list of vanity URLs from AEM. In this blog, we would see how to make the dispatcher work continuously with AEM to get the list of Vanity URLs.

Configuring dispatcher to get the list of Vanity URLs:
In the given example below, for the demonstration purpose, we had set up an AEM instance and dispatcher in a local machine (PC). The same procedure can be applied in real-time applications as well.

Before making changes to the dispatcher configuration file, follow the below steps:

1. Download Vanity URLs Component and install it on publish instance.
2. In order to verify that the installation is done correctly, go to /libs/granite and look for the dispatcher folder. If you have the dispatcher folder created, then you have successfully installed the package.


3. Now, give ‘Read’ permissions to Everyone group to /libs/granite/dispatcher/content/vanityUrls.

Now, let’s make changes to the dispatcher configuration file to get the list of Vanity URLs.

1. Open dispatcher.any file and add /000X { /type “allow” /url “/libs/granite/dispatcher/content/vanityUrls.html” } to the /filter section (X can be replaced with any number).


2. Now, add a caching rule to prevent caching of this URL. In order to do this, add /000X { /type “deny” /glob “/libs/granite/dispatcher/content/vanityUrls.html” } to the /rules section (X can be replaced with any number).


3. Now, it’s time to add the vanity_urls configuration. In order to do this, add the following to /farms section.

/vanity_urls

{/url “/libs/granite/dispatcher/content/vanityUrls.html”

/file “C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/vanity_urls”

/delay 300}

URL: it is the path of the Vanity URL service that runs on the publish instance.

file: It’s the path of the file that stores the list of Vanity URLs.

delay: it’s the time interval in seconds to call the Vanity URL service to get the list of updated Vanity URLs. In the above example, it calls the service for every 5 minutes.

4. Save the file and restart the server.

5. Navigate to the file path mentioned above C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/vanity_urls and you would see the vanity_urls file is created with the list of vanity URLs.




6. Now, you would be able to access the page using vanity URL using dispatcher which in fact would take you to the original URL.

Example: localhost:8080/analog-dark-wash-jean

Note: If you are not able to access the page using Vanity, make sure you have not added .html while creating a vanity URL. If you have added .html to the end of the vanity URL, then remove it.


Above dispatcher configuration is a one-time setup and restart of the server is not required every time we add a new vanity URL on AEM pages. It automatically updates the vanity URLs list with the given time interval.


By aem4beginner

No comments:

Post a Comment

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