6

The links in the main navigation end without a trailing slash, which do not match the canonical tags which end without.

Is there an easy way to make all links throughout the site end with a trailing slash? Please note. I'm not looking for a redirect to force a trailing slash, I'm looking to get the internal inking to include a trailing slash.

Bit of a Magento beginner, looking for an easyish fix if there is one.

  • Why is it important, if you have canonical URL turned on in the settings? Google will know that they are both the same page. – Dan Aug 2 '13 at 16:58
  • 1
    I feel its important to have the site structure that you intend. You shouldn't need to have canonical tags fix what should be correct in the first places, redirects and canonical tags should be the last option if you cannot corrected your site structure. There is also the fact that you lose some 'juice' when using canonical tags and 301 redirects. – moobot Aug 3 '13 at 11:33
  • 1
    I wholeheartedly disagree - the canonical tag is the defacto URL, period, for any page on which it appears, regardless of trailing slashes, querystring params, www/no-www. How do I know? I've accidentally de-listed a site by statically setting all 2000+ pages' canonical to the site's URL, forcing engines to 'delist' all pages save for the home page. – philwinkle Aug 5 '13 at 13:29
  • Not sure what you are disagreeing with?This is a great case for having your canonicals matching your internal linking. – moobot Aug 6 '13 at 2:16
  • Did any of the given answers help you with the issue or do you need more help? – Sander Mangel Aug 9 '13 at 11:59
10

For both categories and products you should be able to do this by setting the 'URL suffix'. Go to the backend System > Configuration Catalog section > Catalog then scroll down to Search Engine Optimisations and give the Product URL Suffix and Category URL Suffix the value /

Don't forget to reindex your Catalog URL Rewrites

  • 1
    Please note that this will work with Community Edition (tested in 1.8.1.0) but not with Enterprise Edition (tested in 1.13.0.2). In EE you'll get an error: "'Only alphanumeric characters and "_" (underscore) symbol is allowed for the "URL Suffix"". – Matthias Zeis Apr 3 '14 at 14:33
  • So what should be the solution in EE? I am having dot at the end of every url in sitemap & dont want any suffix – GunJan Mehta Aug 23 '18 at 9:49
7
+25

As the commenters indicated, there's not really a culture of "smart" url design in ecommerce — efforts are much more focused on the practical effects of how Google (and other search engines and Google) indexes your site based on URLs. That's why URL features are grouped under titles like Search Engine Optimization. Because of that, you're going to have a hard time finding a non-programatic (i.e. "easy-ish") way of doing what you want.

Fortunately, in a stock system (and with well defined extensions), Magento (ultimately) creates all its URLs with the following method

Mage_Core_Model_Url::getUrl

located in the following file

app/code/core/Mage/Core/Model/Url.php

If this is an important feature for you, I'd focus on figuring out how to create a class rewrite for the Mage_Core_Model_Url model class (i.e. Mage::getModel(core/url), and rewrite the getUrl method with something like this

public function getUrl($routePath = null, $routeParams = null)    
{
    $url = parent::getUrl($routePath, $routeParams);
    //your custom PHP code here to ensure the $url 
    //string has no trailing slash

    return $url;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.