URL shortening and resource resolution involving regex
A common use case in AEM based content management, is to map a page to a shortened public URL, and correspondingly resolve a shortened URL to the resource.
While there exists multiple ways to achieve the same, this post discusses one particular option, with the possibility of using regular expressions.
Sample content structure
/content
|- sas-bp (blueprint)
|- en
|- ....
/content
|- sas-se
|- en
|- ....
/content
|- sas-dk
|- en
|- ....
|- sas-dk
|- en
|- ....
Let's say country specific live copies are named as sas-xx as per editorial governance, where xx is the country code.
OSGI Configuration
In AEM 6.1, you can leverage the OSGI configuration for Apache Sling Resource Resolver Factory, in the publish environment.
But it needs two entries if the rule involves regex.
Entry 1 : /content/sas-$1/en$2>/([^/]+)/en(.*)
Entry 2: /content/sas-([^/]+)/en(.*)</$1/en$2
Result
And links to internal pages (in this case the page itself) gets mapped to the corresponding shortened URL.
No comments:
Post a Comment