How do I add links to Magento top.links that redirect to another domain?

How do I add links to Magento top.links that redirect to another domain?

July 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I add links to Magento top.links that redirect to another domain?

Solving Link Redirection Issues in Magento Top.links

As an experienced developer working extensively with e-commerce platforms, I understand the frustration that arises when dealing with link redirections that don’t behave as expected. In this post, we’ll dive into a common issue faced by Magento developers—the inability to redirect top.links to external domains correctly.

Let’s first understand what you’ve already tried and where the problem lies:

  1. You’ve created a custom link using the local.xml file in your theme directory.
  2. Initially, the link points to an internal URL (http://myexampledomain.com/example) correctly.

However, when trying to redirect this link to an external domain (http://myotherexampledomain.com), you encounter two significant issues:

Before we proceed with a solution, it’s crucial to understand how Magento handles links:

  • When creating a top.link, Magento uses relative URLs by default.
  • If you want to redirect to an external domain or even an absolute URL within your own domain, you need to ensure that the prepare parameter is set correctly.

The key to solving this issue lies in properly encoding the URL and ensuring that Magento treats it as a full absolute path:

  1. Open your theme’s local.xml file located at ../myCustomTheme/layout/local.xml
  2. Modify your custom link definition as follows:
<reference name="root">
    <reference name="top.links">
        <action method="addLink" translate="label title">
            <label>example</label>
            <url><![CDATA[http://myotherexampledomain.com]]></url>
            <title>example</title>
            <prepare>true</prepare>
            <!-- Remove any helper functions or parameters from urlParams -->
        </action>
    </reference>
</reference>

Notice the following changes:

  • I’ve used a CDATA section to wrap the external URL. This ensures that Magento treats the string as plain text, preventing it from being interpreted as XML.
  • I haven’t included any helper functions like core/url/getHomeUrl within the <urlParams> tag.

By applying these changes, Magento will correctly interpret the link as an absolute path to an external domain, resolving your redirection issue. This approach ensures that your top.links can seamlessly redirect to any valid URL without concatenating paths incorrectly.

To maintain a clean and efficient codebase, consider these best practices:

  • Always keep your themes as modular as possible. Use child themes for customizations to ensure easy updates.
  • Regularly update your Magento version to benefit from performance improvements and security patches.
  • Avoid modifying core files unless absolutely necessary. Instead, use layout XML files or event observers for most configurations.

Conclusion

In this post, we explored a common pitfall faced by Magento developers when working with top.links—the incorrect redirection of links to external domains. By understanding the Magento link handling mechanism and applying the correct syntax within your theme’s local.xml file, you can resolve this issue effortlessly.

Remember that proper theming practices and regular updates are key to maintaining a stable and secure e-commerce platform. For more in-depth guides on Magento development, consider exploring our comprehensive resources at Laravel Company.

Don’t hesitate to reach out if you have any other questions or need further assistance with your Magento projects!

Themes Configuration Errors

Our network