I'm using Magento 2 CE Version 2.1.0

Taking reference of http://inchoo.net/magento-2/routing-in-magento-2/ for Routing.

My Router.php Controller Code

public function match(\Magento\Framework\App\RequestInterface $request) {

    $identifier = trim($request->getPathInfo(), '/');

    if (strpos($identifier, 'test') !== false) {
    } else {
        //There is no match

    return $this->actionFactory->create(
                    'Magento\Framework\App\Action\Forward', ['request' => $request]

I found @ vendor\magento\framework\App\FrontController.php

public function dispatch(RequestInterface $request)
    $routingCycleCounter = 0;
    $result = null;
    while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
        /** @var \Magento\Framework\App\RouterInterface $router */
        foreach ($this->_routerList as $router) {
            try {
                $actionInstance = $router->match($request);
                if ($actionInstance) {
                    if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
                        $result = $actionInstance->dispatch($request);
                    } else {
                        $result = $actionInstance->execute();
            } catch (\Magento\Framework\Exception\NotFoundException $e) {
    if ($routingCycleCounter > 100) {
        throw new \LogicException('Front controller reached 100 router match iterations');
    return $result;

I have downloaded http://inchoo.net/magento-2/routing-in-magento-2/ gitHub code & installed & working fine. But it's not working for my custom module.

When i type http://localhost/magento2/mymodule/examplerouter it goes to InChoo Controller router not mine.

How to solve this issue?


You created an infinite loop:

  1. you request a URL starting with "test"
  2. your router sets module, controller and action to "moduletest", "test", and "test"
  3. you forward, using this request (the URL is still starting with "test")
  4. Go to (1).

    The inchoo article also explains that:

    Forwarding means that it will break current routers loop and start the loop again

So, if you use forwarding, make sure that the request you forward to is not matched by the router again.

A possible solution for your case is to check if the request already has been modified:

public function match(\Magento\Framework\App\RequestInterface $request) {
    if ($request->getModuleName() === 'moduletest') {

| improve this answer | |
  • I'm getting $request->getModuleName() BLANK. It's not returning any kind of module name. I'm accessing using localhost/magento2/mymodule/frontend-test where fontend-test is URL Identifier like CMS Page URL – Jackson Sep 13 '16 at 1:28
  • @AnkitShah it's due to sortOrder issue in xml, now you have to accept the answer any of the following if you found helpful. – Himanshu Dec 27 '18 at 6:29

If your code is perfect and you still get an error, Then you have to check your sortOrder of router plugin class in di.xml.

As magento official say : https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html

For frontend : enter image description here

For admin : enter image description here

Your sort order should be in between of magento standard router and default router sort order.

| improve this answer | |

I know it's late to answer but it would be helpful for others.

In magento 2.1.10, the standard router sortOrder has been changed to 30, making the custom router (which sortOrder is 22) forward request infinite loop. Change the custom router order > 30 solves the issue.

| improve this answer | |
  • Yes it's working. we have spend 3/4 hours debugging in it, But changing only sort order works. how magento can do this?! :( – Himanshu Dec 27 '18 at 5:37

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.