Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm just working through some PHP to set up a canonical link for each page on one of my websites and I'm wondering what's the correct link for the home page:

Is it:

<link rel="canonical" href="http://www.sitename.com/"/>

Or?

<link rel="canonical" href="http://www.sitename.com"/>

I've always tried to link to the home page without the trailing slash.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Adding or omitting a trailing slash to canonical links really doesn't matter to search engines, providing they both work.

It maybe be best however to stick with one or the other because Google treats each of these URL's separately, which can lead to duplicate content. See this for more on that: Google Webmaster Central Blog: To slash or not to slash

As indicated in that, it may also be wise to do a 301 redirect from the URL that you don't use to the URL that you do use to further avoid duplicate content.

In short, if you don't use a trailing slash in the links in your content, then don't use it in the canonical link either, and follow the same convention in your sitemap too.

share|improve this answer
2  
If you're not experienced with .htaccess file config options, then the simplest way is to look at the headers (e.g., 200 or 301) returned by the server, as covered in the link in my answer. There are online sites that will display server headers, and browser extensions/plugins that will do this too. –  dan Jun 12 '13 at 7:08
2  
FYI: IE is notorious for caching address history. I'd trust Chrome or Firefox more for development. –  dan Jun 12 '13 at 7:16
2  
I think the homepage is a special case here. Chrome and Firefox may hide the trailing slash from the URL (in the same way that they hide the http://) but it is still there. If you visit http://example.com, the request URI the browser will send to the server is for /. –  Tim Fountain Jun 12 '13 at 9:25
1  
Nemmy, you can check if your home page URL has a trailing slash redirect, or not, with a header check such as: webconfs.com/http-header-check.php –  Max Jun 12 '13 at 10:06
1  
@nemmy I don't think anyone is saying that. In any case, I would stick with what Google has to say about it in the link provided. Look at number 4 there. –  dan Jun 13 '13 at 0:05

I feel I should clear this up. Tim Fountain is correct in his comment.

Unlike directories, a domain with a trailing slash is exactly, 100% the same as one without. In other words, it's literally not possible to choose one or the other. So it makes zero difference which you put into your canonical.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.