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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Dynamically redirect to appropriate AEM page that is SEO friendly

Avatar

Level 2

I have a case where I need to read URL's and dynamically redirect to the right product listing page. i.e. When hitting a product detail page, if the current product is out of stock, I want to handle logic and redirect to a product listing page that displays products within the same category.

 

What is the best approach to this which is also SEO friendly? Would there be a way to dynamically redirect within the dispatcher or is this something a custom Java Servlet should handle?

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I agree with @anish-s , but rather than handling via servlet the best approach (in my personal opinion 🙂) would be a Filter. You can check if the request path is product path and send only those paths for further processing with whatever logic you have to find the valid/active products. Rest of the requests , you can let pass through.

 

eg: 

Veena_Vikram_0-1646979739456.png

Hope this helps

 

Veena ✌

View solution in original post

2 Replies

Avatar

Level 10

Hi @akatsuki07 ,

There has to be a logic based on which the page should redirect. To check if the product is out of stock, the call has to go to the server to get the count. Dispatcher won't be able to handle this since there is no identifier that dispatcher would have for out of stock product. 

You can handle this logic in your client side code (javascript) if the product component is using ajax. From there is the response for it is out of stock you can forward the request in js snippet using 

window.location.href="target page path"

Else you can handle it in model class or servlet. 

Avatar

Correct answer by
Community Advisor

I agree with @anish-s , but rather than handling via servlet the best approach (in my personal opinion 🙂) would be a Filter. You can check if the request path is product path and send only those paths for further processing with whatever logic you have to find the valid/active products. Rest of the requests , you can let pass through.

 

eg: 

Veena_Vikram_0-1646979739456.png

Hope this helps

 

Veena ✌