Magento – Add custom url rewrite for Magento 2

magento2url-rewrite

Currently I struggle on a following problem. How can we have a url http://www.example.com/custom/custom/query which would point to http://www.yourwebsite.co.uk/custom/custom/index assuming that query can be anything. (without using .htaccess)

I did it in Magento 1 using url_rewrite in config.xml like this:

<rewrite>
    <fancy_url>
        <from><![CDATA[/custom\/custom\/(.*)/]]></from>
        <to><![CDATA[/custom/custom/index/]]></to>
        <complete>1</complete>
    </fancy_url>
</rewrite>

Is it possible (in anyway) in Magento 2?

Thanks

Best Answer

You can implement this logic in custom router (\Magento\Framework\App\RouterInterface). See \Magento\UrlRewrite\Controller\Router as example

Related Topic