Magento redirect to order view

Magento redirect to order view

July 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento redirect to order view

Solving Magento Admin Redirect Issues: A Comprehensive Guide

Redirection within the Magento admin interface can often prove challenging for developers due to its complex architecture. In this guide, we’ll address a common issue faced by developers when attempting to redirect users from a custom backend module to the admin/sales_order/view page.

Understanding the Magento Admin Redirect Mechanism

Before diving into the solution, let’s briefly understand how Magento handles admin redirection:

  1. Base URL Structure: The base URL for your Magento admin interface is typically set in the core_config_data table under the path web/secure/base_url (for SSL) or web/unsecure/base_url (for non-SSL).

  2. URL Generation: Mage::helper(‘adminhtml’)->getUrl() generates URLs relative to the admin base URL.

  3. Redirect Process: When a redirect is triggered, Magento appends this relative URL to the current base URL and sends it as an HTTP response header.

The Problem: Magento Cutting Off ‘Admin’ from Redirect URL

You’ve encountered an issue where Magento is stripping off the ‘admin’ prefix from your redirected URL. This happens because:

  1. When you call Mage::helper(‘adminhtml’)->getUrl(), it generates a relative URL.
  2. In your case, since there’s no other path specified (only ‘sales_order/view’), it assumes this path is relative to the current context.
  3. Magento then appends this relative path to the current URL, which results in the ‘admin’ being cut off.

The Solution: Using Correct Relative Pathing

To resolve this issue, you need to specify the full admin path when generating the URL. Here’s how to achieve it:

  1. Full Admin Path: Instead of passing only ‘sales_order/view’, include the complete admin path as a parameter.
  2. Use Mage_Adminhtml_Block_Poll::getUrl(): This method is designed specifically for generating URLs relative to the admin context.

Here’s the corrected code snippet you should use:

Mage::app()->getResponse()
    ->setRedirect(
        Mage::helper('adminhtml')->getUrl(
            'admin/sales_order/view',
            array('id' => $orderId, '_current' => true)
        )
    );

Breaking Down the Solution

  1. Array Parameter: We’re passing an associative array as a parameter to the getUrl() method.
  2. ‘id’ Key: This represents the order ID you want to view.
  3. ‘_current’ Key: This flag tells Magento to use the current admin context for URL generation, ensuring the ‘admin’ prefix is preserved.

Conclusion

In this guide, we’ve explored the intricacies of Magento’s admin redirection and provided a comprehensive solution to redirect from a custom module to admin/sales_order/view. By understanding how Magento handles relative URLs within the admin context, you can now effectively generate correct redirects without losing the ‘admin’ prefix.

Remember, following best practices like using appropriate helper methods (Mage_Adminhtml_Block_Poll::getUrl()) and passing the necessary parameters can save you from common pitfalls in Magento development.

For more detailed information on Magento’s URL routing and redirection, I recommend checking out our in-depth article on Magento URL Routing Explained.

Happy coding!

Database Extensions Admin Configuration

Our network