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.
SOLVED

AEM 6.2 Dispatcher rewrite rule

Avatar

Level 3

Hi All,

Can someone please help to overcome this rewrite rule problem? I have an Level4 category page and want to redirect to an specific page.

 

Below is the page hierarchy - added URL of each pages

Outdoors -> Outdoor Tools & Equipment -> Lawn Mowers -> Robotic Lawn Mowers

When I click "Robotic Lawn Mowers" page it goes to below URL.
https://dtq.com/pl/Robotic-lawn-mowers-Lawn-mowers-Outdoor-tools-equipment-Outdoors/4294612702

 

What I need is, when I click "Robotic Lawn Mowers" page it should redirect to below URL. Instead of 'pl' it should redirect to 'c'

https://dtq.com/c/Robotic-lawn-mowers-Lawn-mowers-Outdoor-tools-equipment-Outdoors

 

Below are some sample rewrite rules which we have for l2/l3 category pages:

RewriteCond %{REQUEST_URI} ^/dtq/(mobile|desktop)/c/Departments$
RewriteRule ^/dtq/(mobile|desktop)/c/Departments$ /content/dtq/$1/en_us/Departments.$1.html [PT]

 

RewriteCond %{REQUEST_URI} ^/dtq/(mobile|desktop)/c/(.*)$
RewriteRule ^/dtq/(mobile|desktop)/c/(.*)$ /content/dtq/$1/en_us/Departments/$2.$1.html [PT]

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hope, that rule worked, if not

Here I have listed re-write rules samples, you can get more ideas on rules from this

It contains details about flags too.

https://aemhub.blogspot.com/2020/12/basic-dispatcher-url-rewrites-rules.html

 

View solution in original post

10 Replies

Avatar

Level 3
Hi All - Anybudy knows how to achieve this ?

Avatar

Level 4

These rules does not gives us the clue how "c" getting changed to "pl". Can you mention the rootcause/rule from where it getting changed so we can correct that. Also do mention short url to full url mapping to understand content structure which might help.

Regards

Praveen

Avatar

Level 3

Thanks Praveen for the response. /c/ content is coming from author and /pl/ page contents are coming from separate Nodejs code. So only till /c/ is under AEM scope. I looking for a rewrite rule on dispatcher that redirects to 'c'  URL when I click "Robotic Lawn Mowers" - https://dtq.com/pl/Robotic-lawn-mowers-Lawn-mowers-Outdoor-tools-equipment-Outdoors/4294612702

Avatar

Community Advisor
did you try by giving complete URL (hard coded) ?, if that works , then you can apply regular expressions

Avatar

Level 3

I have tried below rule but it is not working still...

 

RewriteCond %{REQUEST_URI} ^/dtq/pl/Robotic-lawn-mowers-Lawn-mowers$
RewriteRule ^/dtq/pl/Robotic-lawn-mowers-Lawn-mowers$  /content/dtq/desktop/en_us/Departments/Outdoors/Outdoor-tools-equipment/Lawn-mowers/Robotic-lawn-mowers.desktop.html [PT]

Avatar

Level 4

 

As you are looking for a rewrite rule on dispatcher that redirects to 'c'  URL

https://dtq.com/pl/Robotic-lawn-mowers-Lawn-mowers-Outdoor-tools-equipment-Outdoors/4294612702

 

Try below:

#RewriteCond %{REQUEST_URI} !^/pl/(.*)
RewriteRule "^/pl/(.*)\$" "/c/$1" [R,L]

Avatar

Level 3
Yes Praveen. Sure will give it a try. Can you please clarify what does $1 & [R,L] refer too?

Avatar

Level 4

"^/pl/(.*)\$" -> This means what is present after /pl/ copy it

and replace url with "/c/$1"

when $1 will be replaced by copied content.

R means rewrite, L flag (Last) which means it won't have to traverse a huge list of rules like JCR Resolving has to do. 

 

Avatar

Correct answer by
Level 4

Hope, that rule worked, if not

Here I have listed re-write rules samples, you can get more ideas on rules from this

It contains details about flags too.

https://aemhub.blogspot.com/2020/12/basic-dispatcher-url-rewrites-rules.html

 

Avatar

Level 3
Thanks Praveen, will revert back with an update once i complete my verification