Search code examples
urlmagentoslash

Ignore the slash in Magento <url>


I’ve created a menu in page.xml and it looks like this:

<reference name="primary.menu">
<action method="addLink" translate="label title">
<label>Test</label>
<url>test.html</url>
<title>Test</title>
<prepare>1</prepare>
<urlParams/>
<position>10</position>
<liParams>dark-gray</liParams>
<aParams></aParams>
<beforeText></beforeText>
<afterText></afterText>
</action>
...................

The class used for the primary.menu block is extending the Mage_Page_Block_Template_Links class from Magento’s core.

The problem is, that when I click this link it goes to ‘www.mydomain.com/test.html/’ which is not working. My question is what should I do in order to stop the last ‘/’ from showing in the url?


Solution

  • I think that <prepare>1</prepare> is building your URL query (in the absence of a dedicated helper to supply the URL) and as a result is prefixing your URL with the domain (which is what you want), but it is also appending a trailing slash (which is what you don't want)

    1. Either create a helper to supply the "proper" URL.
    2. If the page is a Magento CMS page, use that helper (preferred)
    3. Use <prepare/> and <url>/test.html</url> (hack alert!)

    To use a Magento CMS helper to add a link

    <action method="addLink" translate="label title before_text" module="cms">
      <label>Test</label>
      <url helper="cms/page/getPageUrl">
        <page_id>1</page_id>
      </url>
      <title>Test</title>
      <prepare/>
      <urlParams/>
      <position>10</position>
      <li/>
      <a/>
      <before_text/>
      <after_text/>
    </action>