Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

AEM 6.2: Url Shortening using sling mapping for multi-language site

Avatar

Level 4

Hi All,

I have a use case for url shortening for my multi-language site (Url mapping I am able to solve . Problem is only with shortening in links and hrefs). Would like to hear from you guys if this is achievable or not with Sling mappings.

My page structure and expected shortened url from anchor tags  is as follows.

/content/<companyname>/en/abc.html --> www.<companyname>.com/abc

/content/<companyname>/en/xyz/def.html --> www.<companyname>.com/def

/content/<companyname>/es/abc.html -->www.<companyname>.com/es/abc

/content/<companyname>/es/xyz/def.html -->www.<companyname>.com/es/def

Basically for non english pages i want to have the language code prepended before the page name.

4 Replies

Avatar

Community Advisor

Please check the Rewriting is not disabled in Day CQ Link Checker Transformer and change the Rewrite Elements configuration as required. This will rewrite all the link and href URL's to shorten URL's as configured in the Sling Mappings.

Regards

Albin I

www.albinsblog.com

Avatar

Level 4

Hello Albin, the question is on the feasibility of writing a regex for Url shortening. I know I can write a regex to match the inbound requests and map them to resources.  I need to know if outbound can be controlled using a regex

Avatar

Level 10

You should be able to rewrite all those links (href), if you are using org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl and

resolve.map() from resource resolver when creating them

Avatar

Level 3

Yup that is completely feasible. Sling Mappings are designed for exactly that purpose, you just need to write correct regular expression.

But my question is - do you really need that xyz transformation? As far as I can tell ommiting xyz in path might get conflict with another zyx folder in the same lever having the same page name. I am just making sure that its what you have designed, because if it will turn out that this was a just mistake and you need to get back to original path architecture would be quite hard to preserve old links with new one (if you care at all).