0

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

http://localhost/magento2_beta/index.php/faq/category/view/tags/abc/

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

How to do it?

1 Answer 1

4

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">
    <arguments>
        <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>
            </item>
        </argument>
    </arguments>
</type>

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

https://github.com/magento/magento2/blob/merchant_beta/app/code/Magento/Cms/etc/frontend/di.xml

Your Answer

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

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