How to redirect magento admin page to different controller action?

How to redirect magento admin page to different controller action?

October 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to redirect magento admin page to different controller action?

Redirecting Magento Admin Page to a Different Controller Action

As a Magento developer, you may often find yourself needing to redirect from one admin page to another, or to a different controller action entirely. This can be particularly useful when building custom modules that interact with core functionality like the coupon generation system.

In your case, you’re looking to redirect from an edit page of your custom module to the default sales coupon edit page using Magento’s built-in routing capabilities and grid functionality. Let’s walk through a step-by-step solution to achieve this redirection.

Understanding the Current Situation

First, let’s clarify what’s happening in your current setup:

  1. You have a custom module with a Grid.php file that includes a getRowUrl() method.
  2. This method is currently trying to redirect using the URL helper and the admin route for the promo code controller.
  3. However, when you call this method, it’s not preserving the “admin” part of the URL, leading to an incorrect redirection.

The Root Cause: Missing Admin Key

The issue lies in how Magento handles admin routes. When generating URLs within the admin context, you need to explicitly include the “admin” key in your route parameters. This tells Magento that you’re dealing with an admin-related route and ensures it includes the necessary prefix in the generated URL.

The Solution: Modifying getRowUrl Method

To fix this, we need to modify your getRowUrl() method to ensure it correctly generates a URL within the admin context:

public function getRowUrl($row)
{
    return $this->getUrl('admin/promo_quote/edit', array(
        'id'      => $row->getId(),
        'key'     => Mage::helper('adminhtml')->getUrl('adminhtml/desktop/token')
    ));
}

Here’s what we’ve done:

  1. We’re still using the getUrl() helper, which is responsible for creating URLs based on Magento’s route configuration.
  2. The first parameter is the route name—we’re passing ‘admin/promo_quote/edit’ to specify that we want to redirect to the edit page of the promo quote controller within the admin context.

The second parameter is an array of parameters:

  • 'id' is set to $row->getId(), which retrieves the ID of the current row in your grid.
  • We’re using Mage::helper('adminhtml')->getUrl('adminhtml/desktop/token') to retrieve a valid admin token for session authentication.

Incorporating Security Tokens

Notice that we’ve included a security token in our URL parameters. This is crucial because Magento uses tokens to ensure the authenticity of admin URLs and prevents unauthorized access. Always include these tokens when generating admin URLs programmatically, especially when dealing with potentially exposed endpoints like grid row links.

In your current setup, you’re already including the key parameter in your target URL, which means you’ve set up the necessary token generation somewhere else in your module. However, it’s important to ensure that this token is generated and validated correctly on both the client and server sides for optimal security.

Testing Your Solution

With these changes, when you click an edit link in your custom grid, Magento should now redirect you to the correct URL with the “admin” prefix preserved:

http://localhost/magento2/index.php/admin/promo_quote/edit/id/44/key/af601cf21208c082e697be71620f2e88/

This URL properly includes the “admin” prefix and should take you directly to the default sales coupon edit page within the admin panel.

Conclusion

Redirecting between admin pages in Magento requires a deep understanding of the framework’s routing and URL generation mechanisms. By correctly using the getUrl() helper with the appropriate route names and parameters, you can achieve seamless navigation between different controllers within the admin context.

Always remember to include security tokens when dealing with admin URLs, especially those exposed through grid links or other user-facing elements. This helps maintain the integrity of your admin sessions and protects against potential security breaches.

For more in-depth guides on Magento development best practices, feel free to explore our Magento Development category at Laravel Company. We regularly publish articles covering everything from theme customization to advanced module development strategies.

Happy coding!

Extensions Admin Errors

Our network