Apache rewrite rule for mapping content path by hiding the project structure from end users. | Community
Skip to main content
Level 2
September 11, 2023
Solved

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

  • September 11, 2023
  • 3 replies
  • 1511 views

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]

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shashi_Mulugu

@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

3 replies

Shashi_Mulugu
Community Advisor
Shashi_MuluguCommunity AdvisorAccepted solution
Community Advisor
September 11, 2023

@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

aanchal-sikka
Community Advisor
Community Advisor
September 11, 2023

@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-shortening---aem-6-.html. 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
kautuk_sahni
Community Manager
Community Manager
September 12, 2023

@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