Magento URL Suffix: How to Add a Trailing Slash

by admin on January 25, 2010

After more playing around with search friendly URLs in Magento I came across a bug in the rewrite management. Essentially, changing the URL suffix on category and product URLs to ‘/’ (slash character) generates a 404 page on all URLs.

To make this work, change line 178 in “app/code/core/Mage/Core/Model/Url/Rewrite.php” from

$requestPath = trim($request->getPathInfo(), ‘/’);

to:

$requestPath = ltrim($request->getPathInfo(), ‘/’);

 

Works fine for me!

{ 3 comments… read them below or add one }

Rodney February 10, 2010 at 9:40 am

Great post thanks! Any idea how I can add a trailing slash to the non product/catalog pages? The contact page, cms pages, etc.

Any help with that would be greatly appreciated! Thanks

admin February 10, 2010 at 2:19 pm

Hey Rodney,

From what I remember this won’t apply to other pages as I don’t think they’re controlled by the permalink structure.

Not sure why you’d want a trailing slash anyway- my intention was to do so on product & category URLs for SEO purposes so it matched the existing URL structure

Eric June 9, 2010 at 2:14 pm

Dude, you rock. Thanks for that. I even had to stare at what you did for a while to see the ‘l’. Google lets us know that you don’t want non-trailing slash & trailing slash URL’s pointing to the same place – so fill your site with or the other…Cheers.

Leave a Comment