Rewrite Rules in AEM Dispatcher are not working for AEM - React SPA | Community
Skip to main content
Level 2
April 20, 2021

Rewrite Rules in AEM Dispatcher are not working for AEM - React SPA

  • April 20, 2021
  • 3 replies
  • 6068 views

We are using AEM - React as a SPA.
The Rewrite Rules which are configured for URL shortening were not working with this AEM-React SPA.

We have made some changes in HierarchyPageImpl class so that :path will be specific to the short URL. And the changes are working fine.

But, we have a new use case where we a URL for which there will be different values for a query param. And based on that I need to load a specific page.
Ex:

When users access the below URLs, I need to check the param value and rewrite the rule based on that.

I am able to load those pages but the content for them is still on https://domain/abc page.

https://domain/abc?page=page1

https://domain/abc?page=page2


Below are the Rules I have configured:

RewriteCond %{REQUEST_URI} ^\/abc [NC]
RewriteCond %{QUERY_STRING} ^page=page1 [NC]
RewriteRule ^/(.*)$ /content/page1.html [L,PT]

 

RewriteCond %{REQUEST_URI} ^\/abc [NC]
RewriteCond %{QUERY_STRING} ^page=page2 [NC]
RewriteRule ^/(.*)$ /content/page2.html [L,PT]




I am not able to figure out how this can be handled.

 

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

3 replies

Asutosh_Jena_
Community Advisor
Community Advisor
April 20, 2021

Hi @papenaarun 

 

If I understand the requirement, based on query param you want to redirect to some destination?

for both the query param the destination URL is same or different?

 

RewriteCond %{REQUEST_URI} ^/abc
RewriteCond %{QUERY_STRING} ^page=page1$
RewriteRule (.*) /somepage [R=302,L]

RewriteCond %{REQUEST_URI} ^/abc
RewriteCond %{QUERY_STRING} ^page=page2$
RewriteRule (.*) /someotherpageurl [R=302,L]

302 can be updated with 301 once the development is completed.

 

Thanks!

Level 2
April 20, 2021
ideally it has to be page1.model.json for /page1 and page2.model.json for /page2 which we are making from dispatcher
arunpatidar
Community Advisor
Community Advisor
April 20, 2021

Hi,

I think your rules look fine, it just SPA app is not able to find out the pass-through link instead using the original requested link. TEST RESULT

Arun Patidar
Level 2
April 20, 2021
Yes. For SPA entire page content is based on <pagename>model.json. And this will called internally from clientlib-react. While rewriting the URL in dispatcher page will be loaded but the model.json will be of the page which we are accessing from the browser.
Nikhil-Kumar
Community Advisor
Community Advisor
April 21, 2021

@papenaarun - As per my experience with AEM SPA, you need to have one more rewrite rule for model.json as well.

Thanks,
Nikhil Kumar

Level 2
April 22, 2021

Yes, but how do we know which page model.json has to load?

Because I will be receiving the request as abc.model.json

September 11, 2023

Hi ,

 

Did you get this resolved? What was the final rule that you added to resolve? Can you also share the full list of dispatcher rules you setup to resolve?