It is a quite simple tutorial with 2 steps:
Step 1:
Create di.xml file at app/code/[Name space]/[Your Module]/etc
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="MagentoCmsControllerIndexIndex" type="[Name Space][Your Module]ControllerCmsIndex" /> </config>
In this example, we will rewrite controller Magento/Cms/Controller/Index/Index. In which, [Name Space][Your Module]ControllerCmsIndex will be used to override MagentoCmsControllerindexIndex –the homepage in original Magento 2.
Step 2: Define an overriding controller class
You need to create Index.php in app/code/[Name Space]/your Module]/Controller/Index
<?php
namespace [Name Space][Your Module]ControllerIndex;
class Index extends MagentoCmsControllerIndexIndex
{
public function execute($coreRoute = null)
{
// todo
}
}
Done! I’m sure that you can follow this tutorial without any difficulty.

