How do I use the canonical directive to control which version of my content ranks?

Part of the PDF SEO Guide


When the same content exists as both a PDF and an HTML page, Google needs to decide which version to index and rank. Without guidance, it makes that call on its own - and it often picks the PDF, especially if the PDF has accumulated more inbound links. The canonical directive is how you override that.

Key Takeaways

  • Add a Link header to the PDF response: Link: <https://example.com/your-html-page/>; rel="canonical"
  • This shifts ranking authority toward the HTML page without redirecting users - bookmarks and direct links still work.
  • In Apache: use <Files "your-document.pdf"> and Header set Link in .htaccess. In Nginx: add the header in the location block.

Why PDFs Need a Different Canonical Method

On an HTML page, you add a canonical tag in the <head> section:

<link rel="canonical" href="https://example.com/preferred-url/" />

PDFs don’t have a <head> section. You can’t embed an HTML tag inside a PDF file. Instead, the canonical is declared in the HTTP response header that the server sends when the PDF is requested - before the file content is transmitted.

This is the same canonical signal Google recognizes; it’s just delivered through a different channel. Google’s canonical documentation explicitly covers non-HTML file implementation.


What the Header Looks Like

When a browser or crawler requests your PDF, the server response should include a Link header pointing to the preferred URL:

HTTP/1.1 200 OK
Content-Type: application/pdf
Link: <https://example.com/your-html-page/>; rel="canonical"

The URL in the Link header is where you want search traffic to go. For most situations where a PDF and an HTML page cover the same topic, that’s the HTML page.


How to Set It in Apache

In your .htaccess file, you can target all PDFs in a directory or a specific file:

For a specific file:

<Files "your-document.pdf">
  Header set Link '<https://example.com/html-page/>; rel="canonical"'
</Files>

For all PDFs in a directory:

<FilesMatch "\.pdf$">
  Header set Link '<https://example.com/html-equivalent/>; rel="canonical"'
</FilesMatch>

The second pattern is useful if you have a consistent naming relationship between PDF URLs and their HTML equivalents, but be careful applying it broadly - every PDF in scope will get the same canonical target, which is only correct if they all point to the same page.


How to Set It in Nginx

In the relevant server or location block:

location ~* \.pdf$ {
    add_header Link '<https://example.com/html-page/>; rel="canonical"';
}

For a specific file:

location = /documents/your-document.pdf {
    add_header Link '<https://example.com/html-page/>; rel="canonical"';
}

Using This to Migrate a PDF’s Ranking to an HTML Page

This is the use case most publishers don’t know about. If a PDF is outranking its HTML equivalent, you don’t have to accept that outcome or immediately set up a redirect. Adding a canonical HTTP header to the PDF pointing at the HTML page tells Google to consolidate the link equity and ranking signal on the HTML URL - without breaking the PDF’s URL for users who have it bookmarked or linked.

This is a strong signal, not a hard directive. Google treats it as a significant preference, not an absolute instruction, so it doesn’t take effect immediately. Realistic timeline: 2–4 weeks after the header is set and both URLs have been submitted to Search Console for reindexing.

This approach is appropriate when:

  • You want to shift ranking to the HTML page but aren’t ready to redirect the PDF (e.g., the HTML page is still being built out)
  • The PDF has significant inbound links that you’d lose permanently with a redirect and want to preserve for now
  • You’re testing whether consolidating to HTML improves performance before committing to the migration

When you’re ready to make the change permanent, follow the process in How do I redirect a PDF search result to an HTML page without losing rankings?


What the Canonical Is Not

The canonical header is a preference signal, not a redirect. Users who visit the PDF URL still get the PDF. Crawlers see the header and adjust their indexing accordingly, but users are unaffected. If your goal is to remove the PDF from circulation entirely and send all traffic to the HTML page, a 301 redirect is the right tool, not a canonical.

Don’t set both a canonical header and a 301 redirect on the same PDF URL. The redirect makes the canonical redundant and can cause conflicting signals.


See Also

Digital marketing agency for SEO, paid media, and marketing systems. Flat-rate retainers, no spend markups. Lexington, KY.

Back to articles...