[Home | Contact | What's New? | Products | Services | Tips | Mike |
Living with Schizoaffective Disorder

Fix Invalid Affiliate Links with HTML Entities

Affiliate links such as Amazon's cause your web pages to fail validation with obscure error messages. You can make your links valid by using HTML entities.

Michael David Crawford

Michael David Crawford
May 2, 2012

Copyright © 2012 Michael David Crawford. All Rights Reserved.

I have only just started working on this article. It will take a few days for me to complete it. But simply put:

The Ampersand character "&" is a "Metacharacter" in HTML.

That is, the Ampersand has a special significance in HTML markup, and so cannot be used directly in web pages other that for this specially significant use.

(Actually the Ampersand is a Metacharacter in SGML, the Standard Generalized Markup Language. HTML is a particular variant of SGML. Each such variant is known as an "SGML Application", but one rarely hears that term outside of the standards committees. Other SGML Applications in current use are DocBook, for marking up technical documentation, as well as XML.)

The Ampersand character is used to delimit, that is, to mark the start of HTML Entities. One uses HTML Entities - again, actually SGML Entities - to encode characters or symbols that cannot be expressed directly in the character encoding of the document, or characters that, like the Ampersand, are HTML Metacharacters.

Never, ever place an Ampersand directly in any HTML document other than as the first character of an entity!

One delimits the end of an Entity with the Semicolon character: ";".

& & Ampersand Delimit Start of Entity
< &lt; Less-Than Sign
or Left Angle Bracket
Delimit Start of Tag
> &gt; Greater-Than Sign
or Right Angle Bracket
Delimit End of Tag

Of course we have many reasons to put Ampersands in our documents, most commonly to separate "Query Parameters" in hyperlinks, such as those used for affiliate links, like those provided by the Amazon Associates link generator.

If you try to validate a document containg links with Ampersand-separated query parameters, you're likely to get a message like:

Line 242, Column 44: cannot generate system identifier for general entity "bar".

What that means is that the validator interpreted - and, potentially, any web browser could interpret - the & character that separates query parameters in an affiliate link as the start of an entity, but the word that followed did not match any of the permitted entities from the W3C's web standards documents.

Far worse would be for an Ampersand in one of your hyperlinks as well as the characters that followed to actually form what appears to be a well-known entity, but not one you - or Amazon - intended to appear in the link! That would cause an when your site's visitors tried to click the link.

To fix the validation problem and get rid of the cryptic validator error messages that Ampersands in query parameters cause, replace all of the "naked" Ampersands in your entire document - not just those found in hyperlinks - with &amp;

View the Source of this particular web page for some examples of what I'm talking about. You'll see that I use some entities to denote Ampersands so this page has no trouble validating.

[Home | Contact | What's New? | Products | Services | Tips | Mike]