Canonical page: rel=canonical

One page is often reachable under several URLs: with and without www, with tracking parameters such as UTM tags, as a print version. For a search engine these are different pages with the same text. The canonical URL tells it which one is the main page, so that the copies do not compete with it in the results.

The canonical tag

Put a link element into the head of every copy, pointing to the main URL:

<head> … <link rel="canonical" href="https://www.example.com/docs/install/"> … </head>

Rules

Canonical in an HTTP header

A PDF or another file without a head gets its canonical as an HTTP header:

Link: <https://www.example.com/docs/install/>; rel="canonical"

On Apache the header can be set in .htaccess, see .htaccess.

Canonical or redirect

When the old URL should no longer be shown at all, for example after a move, use a 301 redirect instead: the visitor and the search engine both land on the new page. Canonical is for copies that must stay reachable. Redirects are explained in Redirects.

Check a page

Look for the tag in the HTML with curl:

curl -s https://www.example.com/docs/install/ | grep -i canonical

For the header variant, ask for the headers only:

curl -sI https://www.example.com/docs/file.pdf | grep -i '^link:'

Article authors: Andrei Olegovich, Klavdiya Kondakova