Skip to main content
Level 2
Mar 31, 2023 7:13 AM UTC
Solved

Add .html to sling:internalRedirect

Only on author instance I want to do mapping for URLs without .html. I have written the regex for sling:match. My use case is like, when a user hits URL like /content/we-retail/en is should redirect to /content/we-retail/en.html . ie, I want to append .html to whichever path the user is hitting, if it doesn't have .html and also I want to do this only for AEM author.

 

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Rohit_Utreja
Rohit_UtrejaAccepted solution
Community Advisor
Mar 31, 2023 7:38 AM UTC

Hi @vaishnav_s ,
You can write a Rewrite rule in AEM dispatcher. Something as mentioned below.

RewriteRule ^/(.*)$  /$1.html [R=301,L]

 If you want to handle it within AEM, Apache Sling Resource Resolver Factory can be used.

Please refer below article for more details.

https://blog.3sharecorp.com/shortening-urls-in-aem

BR, Rohit

2 replies

Rohit_Utreja
Community Advisor
Rohit_UtrejaCommunity AdvisorAccepted solution
Community Advisor
Mar 31, 2023 7:38 AM UTC

Hi @vaishnav_s ,
You can write a Rewrite rule in AEM dispatcher. Something as mentioned below.

RewriteRule ^/(.*)$  /$1.html [R=301,L]

 If you want to handle it within AEM, Apache Sling Resource Resolver Factory can be used.

Please refer below article for more details.

https://blog.3sharecorp.com/shortening-urls-in-aem

Translate
BR, Rohit
JeevanRaj
Community Advisor
Community Advisor
Mar 31, 2023 4:17 PM UTC

You can use etc mapping to map incoming requests to proper resource. Check out this article.

https://medium.com/tech-learnings/how-to-implement-extension-less-urls-in-aem-a3136c71b232

Translate