Page 1 of 2
htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun Apr 24, 2011 2:45 am
by ozone100
Is it possible to add a trailing slash at the end of URLs?
I have a background in SEO and I am a perfectionist when it comes factors that could negative affect a pages ability to rank. In Google's eyes,
http://www.beerpongstadium.com/about is a different page than
http://www.beerpongstadium.com/about/. That said, I want all pages to end with a trailing slash. Anyone know how I could add this trailing slash at the end of URLs while keeping my urls seo friendly?
Thanks.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun Apr 24, 2011 3:29 am
by Xsecrets
while I get that about is a different page to about/ in googles eyes who ever said that the trailing slash helps seo?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun Apr 24, 2011 4:07 am
by ozone100
The trailing slash helps seo because it creates only one version of the page...it's a canonical issue.
It does a few things:
- It lets google know which version of the page is the actual version
- It avoids duplicate content issues and penalties associated with duplicate content (pages aren't competing to rank for the same keyword)
- It condenses "link juice," if you have links to mysite.com/page and mysite.com/page/ they are being divided rather than consolidated. Links are the biggest factor in ranking a page so every little bit helps.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Mon Apr 25, 2011 5:47 am
by ozone100
So since it is useful for rankings to have a trailing slash at the end of a URL, does anyone know how to do this?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Mon Apr 25, 2011 5:58 am
by Xsecrets
it has no affect whatsoever on link duplication or canonical issues. As long as all your links are the same it makes no difference if they have the trailing slash or not.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Wed Apr 27, 2011 2:29 am
by boltsabre
sorry, but ozone100 is spot on, it does make a difference - a big differnce. If you have 100 inbound links and:
- 25 link to:
http://www.mypage.com/about
- 25 link to:
http://www.mypage.com/about/
- 25 link to:
www.mypage.com/about
- 25 link to:
www.mypage.com/about/
Then effectivley you are only gaining 25 links to a 'page' instead of the full 100 links. The page is the same as far as content is concerned, yet google does not see it as such, it sees four different pages, and in fact your site can be penalised for duplicate content issues in such a situation - you MUST have an effective .htaccess (for appache server) plan in place with permanent redirects so the user is always directed to your desired version of the url. And it's also a good idea to regularly check back links to the other url versions, and if any exist send the webmaster a nice email and ask them to change the link to your preferred format to gain the most SEO benefit available.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Wed Apr 27, 2011 3:21 am
by Xsecrets
well why would any of the links go to different places if all your pages are rewritten the same? if it's just the person on the other site manually putting in the wrong url. They could just as easily put in the url without the / as to put it in with the /. My argument was never that you don't need htaccess redirects simply that weather with or without the / as long as they are always the same it doesn't matter.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun May 01, 2011 8:52 am
by ozone100
Xsecrets is correct. All that matters is that you have one format. I usually prefer
www.sample.com/ for home and
www.sample.com/page/ for pages. Only thing is that I don't know how to redirect it to one or the other...when working with clients their developers deal with the technical aspect. Anyone know how to automatically add the slash at the end?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun Oct 16, 2011 5:54 am
by deejunit
ozone100 wrote:Is it possible to add a trailing slash at the end of URLs?
I am just curious, did you manage to solve this?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Thu Oct 20, 2011 2:43 pm
by shopfair
I would also love to know if there's a "fix" to add a trailing slash.
regardless of anyone's opinion whether it makes a difference or not !!!
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Fri Nov 04, 2011 4:24 am
by ozone100
This issue is critical to SEO especially with the recent Google Panda updates. Having duplicate URLs puts your website at risk of the Google Panda penalty and can result in significant traffic loss.
If anyone could shed some light on how to modify htaccess to remove/add trailing slashes it would be greatly appreciated.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Fri Jan 20, 2012 11:34 pm
by loki_racer
This is more than a .htaccess issue. You will need to modify OpenCart to generate all links with a trailing slash as well as route them.
/catalog/controller/common/seo_url.php
Code: Select all
- return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
+ return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query . '/';
/catalog/controller/common/seo_url.php after line 10
Code: Select all
if(substr($this->request->get['_route_'],-1) == '/') {
$this->request->get['_route_'] = substr($this->request->get['_route_'],0,-1);
}
This seems to add slashes to the product and category pages.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sat Jan 21, 2012 12:22 am
by deanballard
So to do this do I replace
Code: Select all
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
In the seo_url.php with
Code: Select all
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query . '/';
Then add
Code: Select all
if(substr($this->request->get['_route_'],-1) == '/') {
$this->request->get['_route_'] = substr($this->request->get['_route_'],0,-1);
}
On line 11?
Thanks,
Dean
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sat Jan 21, 2012 1:21 am
by loki_racer
Yes. However, please don't do this on a live site. I am currently testing it in a development environment, as you should as well.
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Mon Feb 06, 2012 12:34 am
by loki_racer
To have all URL's be built with the trailing slash, please modify this as well
Replace:
Code: Select all
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
with:
Code: Select all
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . '/' . $query;
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Tue Feb 28, 2012 4:31 am
by deejunit
loki_racer wrote:This is more than a .htaccess issue. You will need to modify OpenCart to generate all links with a trailing slash as well as route them.
/catalog/controller/common/seo_url.php
Code: Select all
- return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
+ return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query . '/';
/catalog/controller/common/seo_url.php after line 10
Code: Select all
if(substr($this->request->get['_route_'],-1) == '/') {
$this->request->get['_route_'] = substr($this->request->get['_route_'],0,-1);
}
This seems to add slashes to the product and category pages.
Thanks

Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Mon May 07, 2012 11:29 pm
by JackNight
Code: Select all
+ return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query . '/';
as a result I've got double slash for homepage url...

(
like this -
http://shop.com// - < double slash
somebody can help me?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Thu Oct 25, 2012 10:55 am
by Nyrk0
This code add Trailing Slash at the end of SEO category and manufacturers directory-URLs only, not at the end of product page-URLs.
file: seo_url.php
line 76:
Code: Select all
$url .= '/' . $query->row['keyword'];
if ($key == 'manufacturer_id') { $url .= '/'; }
line 85:
Code: Select all
if ($query->num_rows) {
// $url .= '/' . $query->row['keyword'];
$url .= '/' . $query->row['keyword'] . '/';
}
line 113:
Code: Select all
// return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
$pathurl = str_replace('/index.php', '', $url_data['path']) . $url;
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('//','/',$pathurl) . $query;
This works for me at
http://www.globalmac.cl and can be done with vqmod

Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sun Feb 24, 2013 5:56 pm
by SupraTwinTurbo
Has anyone figured out how to successfully add a trailing slash to the end of all SEOed pages (including product pages)? If so can you share the vqmod or code?
Re: htaccess: Add a Trailing Slash at the End of URLs
Posted: Sat Mar 02, 2013 2:17 pm
by yowchuan
Yeah man, I think this is one very important aesthetic aspect. It's like organizing your stuff on your desktop, everyone has a different way of doing it. It would be great if there's a easy way to add/remove trailing slashes on pages.
And there's an interesting discussion on trailing slashes here:
http://stackoverflow.com/questions/5948 ... -preferred