1

I need to redirect my customers when a 404 page is thrown. To achieve this, I need to check whether a particular target path exists in the url rewrite management table.

For example : if my target path is "category1/category2/product1", how would I check that this target path is present in the url rewrite management table, and how to retrieve all information / entries matching the target path shown above ?

0
/**
 * @var \Magento\UrlRewrite\Model\UrlRewrite
 */
protected $_urlRewrite;

public function __construct(
    \Magento\UrlRewrite\Model\UrlRewrite $urlRewrite
) {
    $this->_urlRewrite = $urlRewrite;
}



$this->_urlRewrite->getCollection()->addFieldToFilter('target_path', 'category1/category2/product1')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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