Trailing slashes in URLs and HTTP redirects, SEO benefits

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Trailing slashes in URLs and HTTP redirects, SEO benefits

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

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

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply