0

Want to redirect for the products who are out of stock to custom url

Had tried below url but it did not helped https://stackoverflow.com/questions/4824072/magento-out-of-stock-product-seo-problem

4
  • 301 is permanent redirect. What would seo benefit of doing this instead of using status or visibility to show a 404? I can understand 302 in case comes back in stock? Or are these discontinued products? Commented Jun 12, 2019 at 0:22
  • No they are not discontinued just stock has got over. But in future, there can be such a case where the product can be discontinued Commented Jun 12, 2019 at 1:15
  • In that case do you still want to use 301's? Commented Jun 12, 2019 at 7:17
  • But how to do it. That's my question how to redirect to custom url with 301/302 when there is no stock Commented Jun 12, 2019 at 20:08

1 Answer 1

0

You need to overide this method

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/Controller/Product/View.php#L78

https://magento.stackexchange.com/a/86501/70343

Check stock with something like this

https://magento.stackexchange.com/a/97952/70343

Then redirect using something like this

https://magento.stackexchange.com/a/177876/70343

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.