Mobile app version of vmapp.org
Login or Join
Angela700

: How to specify the canonical URL for downloadable versions of the page (doc, pdf, txt, etc) I've spent much time searching about the situation I'm in, before I post this question. I have a

@Angela700

Posted in: #CanonicalUrl #DuplicateContent

I've spent much time searching about the situation I'm in, before I post this question.

I have a poetry page (working for it currently) and I want users to be able to download poem in PDF, DOC, and TXT, But I don't want to have duplicate content issue, in any means, but also don't want to use no-follow for these files because I want search engines also now about it, because if someone searchis for 'filetype:ext' to find my pages.

I know I can set link canonical in head tag in .htm version but how to do it right for files?

To be clear poems are structured like this:


/poets/name-surname/poems/123.poem-title.htm this is main, next 3 versons are linked from this page, not from anywhere else
/poets/name-surname/poems/123.poem-title.pdf this is pdf version
/poets/name-surname/poems/123.poem-title.doc this doc
/poets/name-surname/poems/123.poem-title.txt this plain text

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela700

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

Google allows you to specify the canonical as an HTTP header. They give an example for canonicalizing one PDF file to another:

Link: <http://www.example.com/downloads/white-paper.pdf>; rel="canonical"


This page shows how to use .htaccess to put these headers in. It would be:

RewriteRule ([^/]+).(pdf|doc|txt)$ - [E=FILENAME:]
<FilesMatch ".(pdf|doc|txt)$">
Header add Link '<http://www.example.com/poets/name-surname/poems/%{FILENAME}.htm>; rel="canonical"'
</FilesMatch>


If these are not static files, it would be easier to output this header from your code. For example, in PHP you might use code like this before outputting the start of the document:

<?php
header('Link: <http://www.example.com/poets/name-surname/poems/'.$poemid.'poem-title.htm; rel="canonical"');
?>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme