Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

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.

 

AEM 6.5 React JS Rewrite Rules SPA

Replies

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

20-04-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!

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

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

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

This is for AEM - React SPA. FYI

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

20-04-2021

Got it. So in both the cases you want to keep the user on the same page but want to show different content based on the query params that are coming as part of the URL?

If that;s the case then you must be using the [PT, L] in the Rewrite rule.

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

Yes, I have placed that. You can check in the post above I have updated it. But the issue is with the content of the page.

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

20-04-2021

Hi @papenaarun 

Rewrite Rule should be PT,L and L should be always at the end as from there it will stop processing. I see you are using it as [L, PT]

 

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

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

 

If the page 1 and page 2 has the content then it will work as there is no other logic that is driven by dispatcher. Please make the above change and try it out.

 

Thanks! 

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

This is what happening. While accessing /abc abc.model.json is getting called and the content coming under this is getting loaded in page. After applying rules, still abc.model.json is getting loaded for both the /page1 and /page2

Avatar

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
Level 2
papenaarun
Level 2

Likes

8 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
papenaarun
Level 2

20-04-2021

ideally it has to be page1.model.json for /page1 and page2.model.json for /page2 which we are making from dispatcher

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

20-04-2021

Hi @papenaarun 

 

When you access /content/page1 does it call page1.model.json? If it's calling it then it should call here as well.

 

Can you please try with the below rules once? Made a minor change. Please make the exact rule change as I have mentioned here for each n every line.

 

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

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