I have custom a module. When I do getUrl, it shows:


So I want an url like: http://localhost/magento2_beta/tag.phtml

How to do it?

1 Answer 1


You may use native rewrite functionality by using menu Marketing->(SEO & Search)->Url Rewrites

Or if you want to implement your own advanced routing - Magento 2 allows to declare your own routers:

Create your router that implements Magento\Framework\App\RouterInterface

Declare your router as additional argument for Magento\Framework\App\RouterList in your di.xml.

<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">
        <argument name="routerList" xsi:type="array">
            <item name="router_unique_code" xsi:type="array">
                <item name="class" xsi:type="string">Vendor\Module\Controller\Router</item>
                <item name="disable" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="string">100500</item>

See example: https://github.com/magento/magento2/blob/merchant_beta/app/code/Magento/Cms/Controller/Router.php


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.