Skip to main content
Level 2
October 8, 2026
Solved

AEMaaCS URL formatting via dispatcher

  • October 8, 2026
  • 2 replies
  • 23 views
Best answer by abid22

I think this worked for me:

# 1. Map the pretty URL to the content path (no PT here)
RewriteRule ^/([a-z]{2}-[a-z]{2})/office/printers/((?:func|cap|paper|vol|speed|brand|feat)-[A-Za-z0-9-]+(?:/(?:func|cap|paper|vol|speed|brand|feat)-[A-Za-z0-9-]+)*)$ \
    /content/mycompany/$1/office/printers.$2

# 2. Replace one remaining "/" with "." per pass, restarting until none are left
RewriteRule ^(/content/mycompany/[a-z]{2}-[a-z]{2}/office/printers\.[^/]+)/(.+)$ \
    $1.$2 [N]

# 3. Once all slashes are gone, pass through
RewriteRule ^(/content/mycompany/[a-z]{2}-[a-z]{2}/office/printers\.[^/]+)$ \
    $1.html [PT,L]

 

Thanks,

2 replies

shrutid56001193
User Group Leader
User Group Leader
October 8, 2026

​@abid22 

You don't need a separate rule for every possible number of selectors.

If the URL structure is predictable, you can use a single rewrite rule to capture the dynamic part of the path and then construct the selector-based URL from it. However, mod_rewrite doesn't have a simple way to dynamically replace an arbitrary number of / characters with . in the captured value.

If you already know the maximum number of segments (7 in your case), try to use separate rules for each supported depth, ordered from the most specific to the least specific. That keeps the rules explicit and easier to maintain.

If the number of segments really needs to grow without a defined limit, It may be cleaner to handle the mapping in the application/servlet layer instead.

https://www.shrutidamle.com/
abid22AuthorAccepted solution
Level 2
October 8, 2026

I think this worked for me:

# 1. Map the pretty URL to the content path (no PT here)
RewriteRule ^/([a-z]{2}-[a-z]{2})/office/printers/((?:func|cap|paper|vol|speed|brand|feat)-[A-Za-z0-9-]+(?:/(?:func|cap|paper|vol|speed|brand|feat)-[A-Za-z0-9-]+)*)$ \
    /content/mycompany/$1/office/printers.$2

# 2. Replace one remaining "/" with "." per pass, restarting until none are left
RewriteRule ^(/content/mycompany/[a-z]{2}-[a-z]{2}/office/printers\.[^/]+)/(.+)$ \
    $1.$2 [N]

# 3. Once all slashes are gone, pass through
RewriteRule ^(/content/mycompany/[a-z]{2}-[a-z]{2}/office/printers\.[^/]+)$ \
    $1.html [PT,L]

 

Thanks,