AEM Cloud Service - Case Insensitive Vanity Rewrite Maps for Dispatcher


Adobe documentation explains adding Vanity urls (or pipeline free url redirects) in AEM Cloud Dispatcher. This post takes it a bit further and explains how to configure Case Insensitive Vanity Map directs.



Redirects /employee -> /content/eaem-cdn-base-64-decode/us/en/employee-home.html
Redirects /EmPlOyEe -> /content/eaem-cdn-base-64-decode/us/en/employee-home.html






1) Upload the redirect map file /content/dam/eaem-redirects/eaem-redirects.txt with following redirects into AEM author and publish it. 

/employee /content/eaem-cdn-base-64-decode/us/en/employee-home.html
/general /content/eaem-cdn-base-64-decode/us/en/home.html


2) Add the following code in dispatcher\src\conf.dispatcher.d\filters\filters.any to allow GET access to above file from publish, run the pipeline and complete deployment.


/0103 { /type "allow" /method "GET" /url "/content/dam/eaem-redirects/eaem-redirects.txt" }



3) Make sure the map file is activated and accessible from publish instance (eg. https://publish-p10961-e1322140.adobeaemcloud.com/content/dam/eaem-redirects/eaem-redirects.txt) before continuing with the dispatcher code changes in next steps, otherwise you might see the following error running pipeline...

RewriteMap: file for map eaemredirects not found:/tmp/rewrites/eaemredirects.map.dir


4) Create file dispatcher\src\opt-in\managed-rewrite-maps.yaml (exact name) add the following code...

maps:
    - name: eaem-redirects.map
      path: /content/dam/eaem-redirects/eaem-redirects.txt



5) Add the following code in dispatcher\src\conf.d\rewrites\rewrite.rules. It converts the incoming urls into lower case before checking for them in map file

RewriteMap eaem-redirects dbm=sdbm:/tmp/rewrites/eaem-redirects.map
RewriteMap lowercase int:tolower
RewriteCond ${eaem-redirects:${lowercase:$1}} !=""
RewriteRule ^(.*)$ ${eaem-redirects:${lowercase:$1}|/} [L,R=301]


6) For deploying to RDE, use the following command

aio aem:rde:install -t dispatcher-config ".\eaem-cdn-base-64-decode\dispatcher\src"






No comments:

Post a Comment