For the custom URL rewrite magento 2 allowed us the concept of the custom router, you need to implement that things into your custom extension like the Magento CMS module do.
- app\code\Vendor\Extension\etc\frontend\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\RouterList">
<arguments>
<argument name="routerList" xsi:type="array">
<item name="customsearch" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Extension\Controller\Router</item>
<item name="disable" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">50</item>
</item>
</argument>
</arguments>
</type>
</config>
- app\code\Vendor\Extension\Controller\Router.php
<?php
namespace Vendor\Extension\Controller;
class Router implements \Magento\Framework\App\RouterInterface
{
/**
* @var \Magento\Framework\App\ActionFactory
*/
protected $actionFactory;
public function __construct(.....
\Magento\Framework\App\ActionFactory $actionFactory,
.....) {
$this->actionFactory = $actionFactory;
}
public function match(\Magento\Framework\App\RequestInterface $request)
{
$identifier = trim($request->getPathInfo(), '/');
//PUT YOUR CUSTOM LOGIC HERE FOR THE URL
$request->setModuleName('digi')->setControllerName('index')->setActionName('index');
// if you want to pass any parameter ->setParam('variable', $value);
return $this->actionFactory->create(\Magento\Framework\App\Action\Forward,['request' => $request]);
}
}