AEM apache redirect rule | Community
Skip to main content
Level 2
August 27, 2024

AEM apache redirect rule

  • August 27, 2024
  • 2 replies
  • 673 views

Hi,

 

We have a requirement to redirect detail/article pages from one location to another location for the scenario of old article bookmarks.

Old article path : /content/project/us/en/category1/articleslist/article1.html

new article path : /content/project/us/en/category2/folder1/articleslist/article1.html

 

The below redirect rule works in local aem dispatcher on windows machine (apache 2.2 windows 64 bit). However, the same rule does not work in aem as a cloud service dev environment.

 

RewriteRule ^/content/project/us/en/category1/articleslist/(.*)$ /content/project/us/en/category2/folder1/articleslist/$1 [PT,L]

 

One difference i could observe is that in my local aem instance, I don't have shortened url paths rules to facilitate article paths  http://domain/us-en/category1/articleslist/article1 

 

should the above rewrite rule be written with * and to remove /content/project/us/en in order to work on higher environments on aemaacs ? Any pointers on this would be of great help.

 

Thanks,

S

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

2 replies

konstantyn_diachenko
Community Advisor
Community Advisor
August 27, 2024

Perhaps, you have rewrite rules above your rule that match first. This can be a potential issue. 

You can try the following rule:

RewriteRule ^(/content/project/us/en)?/category1/articleslist/(.*)$ $1/category2/folder1/articleslist/$2 [PT,L]

I don't know how do you map us-en to /us/en, but you can adapt rule based on the rewrite logic for locale.

By the way, if you need to redirect old locations (bookmarks) to new location, you need to use 301 redirect:

RewriteRule ^/([a-z\-]+)/category1/articleslist/(.*)$ $1/category2/folder1/articleslist/$2 [L,R=301]
Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
MukeshYadav_
Community Advisor
Community Advisor
August 27, 2024

Hi @srinivasanpa1 ,

You are right, if on higher org url is shortened, below rewrite rules should work

RewriteRule ^/us/en/category1/articleslist/(.*)$ /us/en/category2/folder1/articleslist/$1 [PT]

Also with above rules it will not change the path at client side(i.e. in browser it will remail /us/en/category1/articleslist/(.*))

if you want to show redirect at at client side to the user you may write below rules

RewriteRule ^/us/en/category1/articleslist/(.*)$ /us/en/category2/folder1/articleslist/$1 [R=301,L]

Just for cross checking make sure to put these rewrite rules in starting specially before below (similar) rewrite rule ( where shortened path is getting mapped to content path)

 

 

RewriteRule ^/(.*)$ /content/${CONTENT_FOLDER_NAME}/$1 [PT,L]

 

 

In local also shortened url should work if etc mapping or resource resolver config (whatever present in dev) is available in local.

You may try hitting http://localhost:4502/us-en/category1/articleslist/article1

Thanks