It's quite straight forward to check if a request url exists in a store scope via url_rewrites.

However, I'm wondering if there is a way to check if a custom route exists (as they don't have an entry in url_rewrites).

I.e. if I have


class \MyCompany\MyModule\Controller\Index\All extends \Magento\Framework\App\Action\Action

and declared my frontend route

<route id="mymodule" frontName="mymodule">

How to check if mymodule/index/all is a valid request_path (obviously we can try to request this path and will get a HTTP 200 response but I'm trying to avoid going down that path).

  • 1
    Just trying to save you some time. I went down this route(no pun intended) awhile ago and there isn't really any good way to do it. Commented Aug 31, 2020 at 18:08
  • Thank you, appreciate that. Commented Aug 31, 2020 at 22:41
  • 1
    Check out matchAction method in vendor \Magento\Framework\App\Router\Base. That will return an actionInstance if it is found. For 200 status code, i think, you can try to call execute method from the instance and validate result (depends on response type). Commented Sep 2, 2020 at 11:13


Your Answer

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

Browse other questions tagged or ask your own question.