0

I'm building a little module on magento2 and I can currently access it at mysite.com/test/mymodule. I want to be able to access it at mysite.com.

How can I do that?

I've tried doing a URL rewrite in the admin panel but it didn't work, I either get the 'too many redirects' error when I put '/' as the request path, and nothing happens when I put '\' like another thread suggested. I've also searched how to do it by modifying my XML, with no success.

Can you help me ?

2 Answers 2

1

You can configure default route from admin .

Go to Admin -> Store -> Configuration -> [ General ] -> Web -> Default Pages.

Here is configurations for home page.

Try to add your route as default route, or add your module content to Cms home page

enter image description here

1
  • That seems to work very well! Many thanks!
    – Badong
    Sep 5, 2019 at 12:55
0

You should not add any redirect on it. It is called the Homepage by default.

You can do this work by 2 methods:

Method 1:

You can configure default route from admin .

Go to Admin -> Store -> Configuration -> [ General ] -> Web -> Default Pages.

Here is configurations for home page.

Try to add your route as default route or add your module content to Cms home page

Method 2:

You can follow the below steps to call data on Home page (Root)

  1. First create block, controller & template file. According to this link
  2. After that Call your module phtml file in the home page layout. You can Call Phtml file on CMS Page like this

{{block class="Vendor\Module\Block\BlockClass" template="Vendor_Module::block_file.phtml"}}

So after that Your custom module code will call on Root (homepage).

4
  • How can I find the path to my module ? this one (and the one in the link) aren't working
    – Badong
    Sep 5, 2019 at 12:55
  • You will have to give the file path which you gave in the layout like this <block class="Mageplaza\HelloWorld\Block\Display" name="helloworld_display" template="Mageplaza_HelloWorld::sayhello.phtml" />
    – DJ Dev
    Sep 5, 2019 at 13:01
  • Found it, thanks ! This is going to be useful
    – Badong
    Sep 5, 2019 at 13:56
  • @Badong If it is helpful for you please accept this answer.
    – DJ Dev
    Sep 5, 2019 at 15:03

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.