Canonical Tags In Header For PDFs (Non HTML Files)

Netlify site name: ‘lovely-semifreddo-4bea40’
Custom domain:

My site is PDF heavy and I load 2 variants of every PDF, one optimized for US printers which use the Letter page size, and one for non-US printers which use the A4 page size. This results in 2 URLS for each image which are almost identical e.g.

Google is now identifying these pages as ‘duplicate without user-selected canonical’ so I have removed 1 variant from my sitemap and am trying to put a canonical in the header of one of the pdfs.

I’ve read this document Custom headers | Netlify Docs and created a _headers file.

I’ve tried two approaches after reading How To: Advanced rel="canonical" HTTP Headers - Moz and a few other articles, but neither appeared to work when I inspected the page and searched for canonical.

I’d really appreciate an example of the correct code for the canonical that I can implement.

Thank you!


I don’t see any headers being set at least on your published deploy. How are you setting it?

I’m trying to set them using the _headers file but it’s not working.

I was assuming that the code I was using in the _headers file (which I’ve listed above) was incorrect?

Oh sorry, I missed that code. I thought it was something different as that’s not how you configure headers. Netlify documentation: Custom headers | Netlify Docs already shows how to create headers, so I’m not sure why you tried other formats.

In your case, it could be like:

  Link: <>; rel="canonical"
1 Like

Thanks for the code! I’ve updated the _headers file accordingly, but when I inspect the pdf in chrome I still don’t see anything in the . Is this expected?

This is the URL I was looking on:

I see it:

Even in browser:

1 Like

Thank you so much for your help!

Can I ask what you’re using to get the in browser information?

When I do a standard inspect in chrome’s dev tools I don’t see the canonical.

It’s in the network tab:

1 Like

Thanks again for your help! Problem solved :grinning: