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?

Arnaud
3404 silver badges11 bronze badges
asked Oct 27, 2015 at 6:42

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

answered Nov 9, 2015 at 22:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.