Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Do single quotes work for <link rel='canonical'>?

         

financialhost

10:17 am on Mar 6, 2012 (gmt 0)

10+ Year Member



I am working on a website which is using the canniconnical tag but i have noticed that both URL's are going into the index.

www.example.com/bluewidgets &
www.example.com/bluewidgets?idcode2345

Surely the second URL should not be in the index?

I have noticed the tag is using single quotes.
Is this valid syntax?

<link rel='canonical' href='www.example.com/bluewidgets'>

Google has the instructions as double quotes:
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

Any advice on this one is appreciated.

Thanks

tedster

6:34 pm on Mar 6, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Single quotes are not valid syntax. In non-critical situations you can get away with the single quotes because browser error correction routines have no problem handling it.

But this IS a critical situation, so I'd switch over to double quotes.

lucy24

2:56 am on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Single quotes are not valid syntax.

Says who? Not w3c:
Double style quotes are the most common, but single style quotes are also allowed.

I see single quotes most often in html written by Europeans. It validates either way. (I checked.)

On the original question: Doesn't the "canonical" tag apply only to the bare URL? I thought you had to tell g### explicitly to disregard any parameters (queries) that don't matter.

financialhost

10:11 am on Mar 7, 2012 (gmt 0)

10+ Year Member



Well i have found mixed opinions online about single quotes being valid which is why i am confused.

I have to be sure to be correct before i go and ask the dev team to amend this because no doubt they will argue that single quotes work.

The reason which makes me belive they are not working in this case is because i can found copys of both URL's in the index.

Surely if the caniconical tag was working it should not list both URL's in the index?

financialhost

10:41 am on Mar 7, 2012 (gmt 0)

10+ Year Member



I just realised the caniconical on the website is not escaped:

<link rel='canonical' href='www.example.com/bluewidgets'>

Should it actually be <link rel='canonical' href='www.example.com/bluewidgets' />

Would the /> make a difference?

lucy24

11:06 am on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One form is html. The other is xhtml. Does the page validate?

netmeg

12:01 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are we talking about whether it's valid according to the W3C, or are we talking about whether it works? Because regardless of what the W3C says, it doesn't sound like it's working.

financialhost

12:16 pm on Mar 7, 2012 (gmt 0)

10+ Year Member



Well am i correct in thinking that it can't be working since both URL's are in the index?

If i go to Google and type in www.example.com/bluewidgets there is a listing.

But i can also go to Google and type in www.example.com/bluewidgets?idcode2345 and that is also there.

My understanding is that www.example.com/bluewidgets?idcode2345 should not be in the index if the URL's have consolidated?

Or is my understand incorrect in this matter?

rainborick

3:15 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When it comes to single vs. double quotes, I've never seen Google have any problem dealing with either one. However, in recent years when data in the <head> section has become more important, I have seen many instances where Google appears to ignore tags with invalid/missing self-closing mark-up in the <head> section when the <!DOCTYPE> requires them. In such situations where folks have had problems with getting <meta> descriptions and rel=canonical's handled properly, repairing these tags has seemed to resolve the issue. So it's definitely worth fixing.

netmeg

3:34 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not positive, but I seem to recall that Google hedges their bets and says that they consider rel=canonical to be a "suggestion" and don't promise that they will always use it. Although so far, they've always used it for me.

financialhost

4:02 pm on Mar 7, 2012 (gmt 0)

10+ Year Member



Doc type is <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

So i guess this means i should ask the dev team to add amend the tag to:

<link rel='canonical' href='www.example.com/bluewidgets' />

With />

netmeg

4:42 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there some reason you don't WANT to use normal quotes?

aakk9999

4:54 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are amending the element already to add / then you may as well as for double quotes to be put at the same time:

<link rel="canonical" href="www.example.com/bluewidgets" />

rlange

5:15 pm on Mar 7, 2012 (gmt 0)

10+ Year Member



financialhost wrote:
<link rel='canonical' href='www.example.com/bluewidgets'>

Is that the actual code? If so, the problem may be that the protocol ("http://") is missing. I know that "http://www.example.com/bluewidgets" is OK, and that just "/bluewidgets" is OK, but I've never seen the suggestion that "www.example.com/bluewidgets" would be OK.

I reserve the right to be wrong, of course.

--
Ryan

financialhost

5:23 pm on Mar 7, 2012 (gmt 0)

10+ Year Member



The dev team codes the site and i assume there is a reason why they wanted to use single quotes - apparently some coders prefer to use single quotes in some cases for some reason.

I will request they use double quotes and add the />.

If this thread remains open i will let you all know if this resolved the problem in a few weeks time.

Thanks for all your help - it is really appreciated.

FranticFish

5:56 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I assume there is a reason why they wanted to use single quotes

To avoid escaping double-quotes?

tedster

6:34 pm on Mar 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I stand corrected - both quotes are fine. I've been wrong about this for many years ;(

By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39)

[w3.org...]

Just a guess here. Europeans may tend more toward single quotes because their native language may use a set of double angle quotes - a guillemet: « »