Expand my Community achievements bar.

SOLVED

Apache rewrite rule for mapping content path by hiding the project structure from end users.

Avatar

Level 2

We have a site siteA.com and when someone tries to access siteA.com/content/siteA/us/en/page1.html, it should redirect them to siteA.com/page1.html hiding the content path /content/siteA/us/en/* . 

We need to add redirect rule so all traffic trying to access /content/siteA/us/en/* should go through main URL and hide the project structure.

 

Could someone please help with the redirect rule.

I already have this rule added - RewriteRule ^/(.*)/$ /content/siteA/us/en/$1.html [PT,L]

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Silvia_Joyce_Balraj two further questions,  1. why are you anticipating incoming requests with full path, if it is from one of your webpage first implement url shortening for outgoing urls using etc/maps so that no incoming requests with full urls

2. Do you have any cdn? If yes try to implement these rules at CDN, as these rules should be 301 redirects, and it should be as close to edge as possible.

 

Please refer to below blog for reference

 

RewriteRule ^/content/geometrixx-outdoors/(.*)(\.html)?$ /$1 [NE,L,R=301]

 

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

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

@Silvia_Joyce_Balraj two further questions,  1. why are you anticipating incoming requests with full path, if it is from one of your webpage first implement url shortening for outgoing urls using etc/maps so that no incoming requests with full urls

2. Do you have any cdn? If yes try to implement these rules at CDN, as these rules should be 301 redirects, and it should be as close to edge as possible.

 

Please refer to below blog for reference

 

RewriteRule ^/content/geometrixx-outdoors/(.*)(\.html)?$ /$1 [NE,L,R=301]

 

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

Avatar

Community Advisor

@Silvia_Joyce_Balraj 

 

Masking of paths can be done like this:

 

# Mask the /content/wknd path
RewriteRule ^/content/wknd/(.*).html$ $1.html [R,L]

 

 

  • For URL shortening, please refer and prefer:

https://helpx.adobe.com/in/experience-manager/kb/multi-domain-management-aem-mappings-for-url-shorte...It uses sling mappings, which is a recommended way.

 

For expansion of URLs, you can refer to WKND site https://github.com/adobe/aem-guides-wknd/blob/main/dispatcher/src/conf.d/rewrites/rewrite.rules

 

To better understand rewrite rules, you can refer to section "URL Rewriting" on https://techrevel.blog/2023/09/01/aem-dispatcher-filters-ignoreurlparams-virtualhosts-rewrites/

It also has few examples to explain the rewrites


Aanchal Sikka

Avatar

Administrator

@Silvia_Joyce_Balraj Do you find the suggestions from users useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. 



Kautuk Sahni