Skip to main content
Level 2
Apr 20, 2021 11:07 AM UTC

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

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.

16 replies

Asutosh_Jena_
Community Advisor
Community Advisor
Apr 20, 2021 11:19 AM UTC

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!

Translate
Level 2
Apr 20, 2021 11:41 AM UTC
Not redirect. It should be Rewrite. User end URL shouldn't change. I have already configured and internally page is getting loaded for that. But, the content is not changing as it depends on model.json
Translate
arunpatidar
Community Advisor
Community Advisor
Apr 20, 2021 12:24 PM UTC

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

Translate
Arun Patidar
Level 2
Apr 20, 2021 12:30 PM UTC
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.
Translate
Nikhil-Kumar
Community Advisor
Community Advisor
Apr 21, 2021 4:29 PM UTC

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

Thanks,
Nikhil Kumar

Translate
Level 2
Apr 22, 2021 5:41 AM UTC

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

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

Translate
Sep 11, 2023 3:14 AM UTC

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?

 

Translate