


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
Views
Replies
Sign in to like this content
Total Likes
I agree with @anish-sinha , 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:
Hope this helps
Veena ✌
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.
I agree with @anish-sinha , 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:
Hope this helps
Veena ✌