Magento 2 Custom Controller Redirected to 404 Page – How to Fix

404-pagecontrollersfrontendmagento2

I have a created a frontend controller on location
Namespace/Mymodule/Controller/Schedule.php

namespace Namespace\Mymodule\Controller;
class Schedule extends \Magento\Framework\App\Action\Action
{
  public function execute()
  {
    die("Hello");
  }
}

routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
  <router id="standard">
     <route id="mymodule" frontName="mymodule">
        <module name="Namespace_Mymodule" />
    </route>
  </router>
</config>

Now when I try to manually call this action by http://localhost/magento2/mymodule/schedule (as i am working on localhost) that time I am getting an 404-Not found page.

Where I am going to wrong ?

Thank you in advance.

Best Answer

Your controller structure is wrong it shold be look like Namespace/Mymodule/Controller/Index/Schedule.php

URL is: http://localhost/magento2/mymodule/index/schedule

change namespace to Namespace\Mymodule\Controller\index

Related Topic