Canonical page: rel=canonical
| The canonical tag | |
| Rules | |
| Canonical in an HTTP header | |
| Canonical or redirect | |
| Check a page |
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
- Use the full URL with scheme and host, not /docs/install/.
- The main page itself may carry the same tag pointing to itself. It costs nothing and covers copies you do not know about, for example with parameters added by other sites.
- One canonical per page. Two different ones and search engines ignore both.
- The canonical URL must answer 200: not a redirect, not a 404, not a page closed for robots.
- It is a hint, not an order. A search engine may choose another URL when the pages differ too much.
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