Page 1 of 1

Trailing slashes in URLs and HTTP redirects, SEO benefits

Posted: Wed Aug 29, 2012 10:57 am
by batfastad
When building HTML layouts I usually use relative URLs to pages such as /news or /archives. And when making redirects in .htaccess and PHP I always redirect to the URL without a trailing slash.

From an SEO perspective, should I actually be referring to URLs with a trailing slash at the end?
Google says it doesn't matter so long as you are consistent, otherwise I guess they will penalise you for duplicate content.

From a server perspective (Linux, Apache) not having the trailing slash means the destination could actually be either a file or a directory. Whereas with the trailing slash that can only be a directory and Apache serves the DirectoryIndex document for that directory.

I always make sure I 301 (moved permanently) redirect the URL with a trailing slash to the one without. So that should avoid duplicate content penalties.

But what's better as a general rule?
I don't mind either way, I'd just like to know if either type is preferred/recommended.

Cheers, B

Re: Trailing slashes in URLs and HTTP redirects, SEO benefit

Posted: Wed Aug 29, 2012 2:35 pm
by requinix
The thing about duplicate content is how /path and /path/ might end up showing the same content, but since the URLs are different it's counted as two separate versions. That's the penalty. Apache has DirectorySlash which, when enabled (and it is by default), will automatically 301 /path to /path/ so long as /path is an actual directory it's serving. There are technical reasons why it should too - check the documentation if you're curious.

Personally I think of a site serving pages, not directories. Thus /news. But on the other hand you can consider it as a "directory" of news items, thus /news/ makes sense too. So I say "whatever floats your boat". But like Google said, pick one and use it consistently.

Re: Trailing slashes in URLs and HTTP redirects, SEO benefit

Posted: Wed Aug 29, 2012 2:47 pm
by batfastad
requinix wrote:But on the other hand you can consider it as a "directory" of news items, thus /news/ makes sense too.
And that's what prompted my question really. Because the trend to have search-friendly URLs means you usually see .html appended news items... /news/2012/article.html. So /news/2012/ does make sense as a directory in that respect.

Thanks for the info on DirectorySlash, I did not know that.

Re: Trailing slashes in URLs and HTTP redirects, SEO benefit

Posted: Wed Aug 29, 2012 3:16 pm
by requinix
I imagine the .html extension is mostly because more and more people are getting familiar with filenames and the web. "/news/2012/article.html" fits into the mental model they have of where things (ie, files) are located.