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.mysite.com , the canonical link shows up with a slash at the end:
<link rel="canonical" href="http://www.mysite.com/" />
I know trailing slashes DO matter when 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?
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.