Reputation: 183499
When working with canonical URLs, does a trailing slash make any difference on a root URL?
I put the following canonical tag into my Rails site head:
<link rel="canonical" href="<%= url_for(:only_path => false) %>" />
...to ensure any parameterized URLs resolve to the base URL.
However, when I navigate to http://www.example.com
, the canonical link shows up with a slash at the end:
<link rel="canonical" href="http://www.example.com/" />
I know trailing slashes DO matter when a path element is present in the URL, but thought they didn't matter on root URLs. However, I then ran into Matt Cutts presentation on canonical tags, where he clearly states that they are considered different URLs:
From http://www.mattcutts.com/blog/canonical-link-tag/ (See slide 3):
These URLs are all different:
www.example.com
example.com
www.example.com/
example.com/
Can anyone shed some light on what he means?
Upvotes: 3
Views: 3986
Reputation: 37
URLs which point to directory names (often with the expectation that a web server handler will return some sort of 'index'') without a trailing slash are actually invalid. Most web servers will automagically correct these requests with a redirect to the same URL with a trailing slash added.
So behind the scenes, your request for http://example.com
results in a redirect from the web server to http://example.com/
which is why you're seeing the surprise trailing slash.
The short answer is that proper URI paths matter everywhere- root directory or not. For a deeper and more ranty answer, take a look at this page.
Upvotes: 3