Adding Canonical URL to PDFs | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Dipti_Chauhan

you can write a rewrite rule matching you dam asset path. The rule will add a Link header to the response, with the value of the header being the canonical URL of the PDF.

Something like  

Header set Link 'FILENAME; rel="canonical"'

 

3 replies

sherinregi-1
Community Advisor
Community Advisor
October 3, 2023

Hi @divyat 

You can try by adding the below snippet as part of the rewrite rules

In the dispatcher module you can use "/dispatcher/src/conf.d/rewrites/rewrite.rules" to add the changes

 

RewriteRule ([^/]+)\.pdf$ - [E=FILENAME:$1]

<FilesMatch "\.pdf$"> Header add Link '<http://www.example.com/download/%{FILENAME}e>; rel="canonical"'

</FilesMatch>

 

Also please refer this below link

https://www.danielmorell.com/guides/htaccess-seo/crawling-indexing/put-rel-canonical-on-non-html-resources

 

 

Hope this helps

 

 

Dipti_Chauhan
Community Advisor
Dipti_ChauhanCommunity AdvisorAccepted solution
Community Advisor
October 3, 2023

you can write a rewrite rule matching you dam asset path. The rule will add a Link header to the response, with the value of the header being the canonical URL of the PDF.

Something like  

Header set Link 'FILENAME; rel="canonical"'

 

kautuk_sahni
Community Manager
Community Manager
October 4, 2023

@divyat Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni