How to get the URL of a page/section in Magento admin

How to get the URL of a page/section in Magento admin

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get the URL of a page/section in Magento admin

Getting URLs of Pages/Sections in Magento Admin

Working with URLs in the Magento admin backend can sometimes be tricky, especially when you want to construct or retrieve links to specific pages within your custom modules. In this post, we’ll explore how to get URLs for pages in the Magento admin interface.

Understanding the Problem

When using the getUrl() method inside your controller action with a frontname argument like so:

$this->getUrl('mymodule/controller/action');

You might expect it to return an URL that includes the admin frontend name. However, this is not the case by default. The resulting URL will look something like this:

http://mydomain.com/index.php/mymodule/controller/action

This doesn’t include the necessary admin frontname portion of the URL required for proper routing within the admin interface.

Possible Solutions

There are a couple of approaches mentioned in the Magento community that seem to point in the right direction, but let’s examine them in detail:

Using the Adminhtml Helper

Some discussions suggest using the adminhtml helper to get the URL like this:

Mage::helper("adminhtml")->getUrl();

However, when you try this approach, you’ll find that it doesn’t append the admin frontname either. So while it’s a step in the right direction, it doesn’t fully solve our problem.

Retrieving the Admin Frontname

Another tip shared is to use Magento’s configuration reader to retrieve the admin frontname:

Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');

This does indeed allow you to get the admin node value. But again, this only provides part of what we need - it doesn’t help us construct a full URL.

The Proper Approach

The key lies in combining these approaches correctly within your controller context. Here’s how to do it:

$adminFrontname = Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
$url = Mage::helper("adminhtml")->getUrl($adminFrontname . '/mymodule/controller/action', array('_secure' => true));

In this example, we first retrieve the admin frontname using the configuration reader. Then, we pass it along with our module URL to the getUrl() method of the adminhtml helper.

The resulting $url variable will contain a properly formatted and secured URL that includes the admin frontend name:

https://mydomain.com/admin/mymodule/controller/action

Conclusion

Obtaining URLs for pages in Magento’s admin backend requires a combination of retrieving the admin frontname from the configuration and passing it to the adminhtml helper for URL construction. By following this approach, you can generate valid URLs that properly route within your custom admin modules.

Remember, always ensure your URLs are properly secured by including the _secure parameter when needed.

For more in-depth discussions on Magento development best practices, feel free to check out our Magento Development category. Happy coding!

Extensions Admin Configuration Errors

Our network