Magento How to redirect to homepage after register

Magento How to redirect to homepage after register

July 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento How to redirect to homepage after register

Redirecting New Users to the Homepage After Registration in Magento

As a developer specializing in ecommerce platforms, I often encounter this common challenge when working with clients building online stores using Magento. By default, after a user registers on your site, they are redirected to their account page. However, you may want to direct them to the homepage instead for a smoother user experience.

Understanding the Default Flow

Before we dive into the solution, let’s understand what happens during a user registration:

  1. The user navigates to the “Create an Account” link.
  2. They fill in the necessary details and submit the form.
  3. Magento validates the input data.
  4. If successful, the user is created and redirected to their account dashboard.

The redirect happens because of this line in the customer/register.phtml template file:

$this->getUrl('customer/account/createpost', ['_secure' => true]);

Modifying the Redirect

To change where the user is sent after a successful registration, we need to override this behavior. Here’s how you can achieve this:

Method 1: Override the Customer Controller

You can create an extension that overrides the default customer module by creating a new controller in your custom module.

First, create your custom module (let’s call it Company_Magento2) and enable it in the Magento admin interface.

Then, navigate to the Vendor/Magento2/Controller/Customer.php file and add the following code:

namespace Company\Magento2\Controller;

use Magento\Framework\App\ActionInterface;
use Magento\Framework\Controller\ResultFactory;

class Create extends \Magento\Customer\Controller\AbstractAccount implements ActionInterface
{
    public function execute()
    {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setUrl($this->_url->getHomepageUrl());
    }
}

This code overrides the execute method of the CustomerController. Instead of redirecting to the account dashboard, it redirects the user to the homepage URL.

Method 2: Use Layout XML

If you prefer a cleaner approach without creating a new controller, you can use Magento’s layout XML to redirect after registration. Create a file at Vendor/Magento2/etc/frontend/di.xml and add this content:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Customer\Controller\Account\CreatePost" type="Company\Magento2\Controller\CreatePost">
        <constructor>
            <arguments>
                <argument name="context" xsi:type="object">Magento\Framework\App\Action\Context</argument>
                <argument name="customerRegistry" xsi:type="object">Magento\Customer\Model\Session</argument>
                <argument name="loginHelper" xsi:type="object">Magento\Customer\Helper\Login</argument>
                <argument name="url" xsi:type="object">Magento\Framework\UrlInterface</argument>
            </arguments>
        </constructor>
    </virtualType>
</config>

Then, create the CreatePost file in your Vendor/Magento2/Controller/Customer.php:

namespace Company\Magento2\Controller;

use Magento\Framework\App\ActionInterface;
use Magento\Framework\Controller\ResultFactory;

class CreatePost extends \Magento\Customer\Controller\Account implements ActionInterface
{
    public function execute()
    {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setUrl($this->_url->getHomepageUrl());
    }
}

Conclusion

Both methods should allow you to redirect your newly registered users to the homepage after a successful sign-up. Remember, when working with Magento, it’s essential to follow best practices for maintaining a clean and organized codebase.

For more advanced customization options in Magento 2, I recommend checking out the documentation provided by Laravel Company. They offer comprehensive guides on Magento development that can help you build more efficient ecommerce solutions.

If you have any further questions or need additional assistance with your Magento project, feel free to reach out. I’m always here to help!

Magento 2 Extensions Themes Admin

Our network