0

enter image description here

I want to change the url of the index page for magento 2 store.

I changed the Default Web URL to "custom", but when I go to site.com/custom it gives me a 404 and the index page is still site.com/cms

2 Answers 2

2

Magento has a setting in admin under System > Configuration > Web > Default Pages called “Default Web Url”. Normally this is set to a value of cms, and you specify which CMS page to use in the next option “CMS Home Page”. Magento (of course!) doesn’t use the Default Web Url as you would expect – it is not a simple url string that will redirect the visitor. If you’ve tried to set this to land your users, for example, on a category or product page, you’ll have found out it doesn’t work the way you might think.

The Default Web Url value is interpreted by Magento using the three-part front controller scheme that runs the entire site. The format is like this: frontname/controllername/actionname and you can only have up to three parts specified, the way it’s interpreted (as of 1.3.2.3). For those who aren’t familiar with this scheme, here’s a very brief overview. (visit http://alanstorm.com/magento_controller for a more in-depth discussion) The frontname is defined in a module’s config.xml file. Look in the frontend section under routers and you’ll find a frontName tag. (Magento core modules are all under /app/code/core/Mage). The frontname routes the request to the module’s front controller, which are in the corresponding ModuleName/controllers directory. In there are all the controller files, named as ControllernameController.php and inside those files are the action methods, named actionnameAction().

Throughout the code examples below, replace Mycompany and Mymodule with whatever names you want to use. Be sure to pay attention to capitalization; it’s important and it’s not necessarily consistent or intuitive!

To set up a module that will let you redirect an incoming root website link to wherever you want, first set up a module xml file under /app/etc/modules/Mycompany_Mymodule.xml containing this code: true local

Then, create your company’s module directories:

/app/code/local/Mycompany/Mymodule
/app/code/local/Mycompany/Mymodule/controllers
/app/code/local/Mycompany/Mymodule/etc

Create your config file in /app/code/local/Mycompany/Mymodule/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Mymodule>
            <version>0.1.0</version>
        </Mycompany_Mymodule>
    </modules>
    <frontend>
        <routers>
            <mycompany>
                <use>standard</use>
                <args>
                    <module>Mycompany_Mymodule</module>
                    <frontName>mycompany</frontName>
                </args>
            </mycompany>
        </routers>
    </frontend>
</config>

You will see that we specify a frontend router, called mycompany, indicating that the frontName mycompany should direct the code to Mycompany_Mymodule.

Now, create the controller file in /app/code/local/Mycompany/Mymodule/controllers/PageController.php (the file can be named for whatever controllername you want to specify after the frontname on the url line, in this case the controllername would be “page” all lowercase. The file name should be your controllername with an uppercase first letter, followed by Controller.php)

<?php
class Mycompany_Mymodule_PageController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->getResponse()->setRedirect('/products.html');
    }   
}

Here we define a class named after your module name and front controller name. In that class we have an indexAction() method, which is what gets called if you don’t specify an action name (like mycompany/page). If you want a different action name (like mycompany/page/discounts) you would create a method called discountsAction(). In our indexAction method above, we do a simple redirect, which will send the website visitor to whatever url we want, with no Magento shenanigans to mess with us. Set the admin Default Web Url to “mycompany/page” and it will fire the indexAction and redirect our visitor! Here we have it hard-coded, but it would be simple to set up a definable config setting in admin, if you want a fully-functional module.

0

It doesn't work like this, you need to put the full path : router/controllerName/actionName, look for exemple the 4th filed Default No-route URL, you see the full path cms/noroute/index and no just cms

for more explanation here.

Good luck.

5
  • thanks for the answer, but is there any way to change the site url of the index page?
    – xdev
    Jan 13, 2019 at 15:43
  • the index refer to index.php, this file is in your root Magento project, you can remove it via .htaccess this mean : your redirect your base url from domaine.com/index.php to domaine.com/ check also your base url config if you have the /index, remove it
    – PЯINCƎ
    Jan 13, 2019 at 15:54
  • I want to have different customized path for each storeview (not the store view code), for example, I have two stores: store1, store2, and for each of them I want to have its index page with customized url: site.com/store_one for store1 and site.com/store_two but I don't want to create these two folders in root project
    – xdev
    Jan 13, 2019 at 16:02
  • Please ask a new question, it comes out of your basic question.
    – PЯINCƎ
    Jan 13, 2019 at 16:14
  • ok, I'll do it!
    – xdev
    Jan 13, 2019 at 16:39

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.