How to set X-Robots-Tag in IIS environment based on a certain url?

24 Views Asked by At

I have a HTML page like https://www.example.com/page1.html. On this page, anywhere in the source code exists a link to a PDF file, like <a href="https://www.example.com/a-cryptic-id/file1.pdf">my file</a>. There could be multiple links to multiple PDF files on the same HTML page.

My goal is, using X-Robots-Tag, to set a canonical link for the PDF file to the page, where the file is linked on.

Expected result: https://www.example.com/a-cryptic-id/file1.pdf has a header entry <link rel="canonical" href="https://www.example.com/page1.html">

There are multiple cases, so I'm looking for a solution based on mechanics like all PDF files on this page get the page url into canonical.

I'm in IIS environment.

0

There are 0 best solutions below