1. Home
  2. /
  3. Web Design & Development
  4. /
  5. WordPress
  6. /
  7. How to prevent your website PDFs file from getting indexed in Google?

How to prevent your website PDFs file from getting indexed in Google?

website PDFs file from getting indexed in Google

Introduction

Google indexes PDFs or Doc files in the same way as your website web pages but sometimes we would like to block the PDF or Doc files from getting indexed from the google indexing.

To do so, we can follow the below approach.

Blocking PDF through .htaccess

Add the following piece of code in your website’s .htaccess file

<Files ~ "\.pdf$">
  Header set X-Robots-Tag "noindex, nofollow"
</Files>

Or, to block doc file along with pdf file.

<FilesMatch ".(doc|pdf)$">
Header set X-Robots-Tag "noindex, noarchive, nosnippet"
</FilesMatch>

Or, to block only doc file.

<FilesMatch ".doc$">
Header set X-Robots-Tag "noindex, noarchive, nosnippet"
</FilesMatch>

Blocking PDF through php header

Add the following piece of code at the top your header or php file which serves the PDF or Doc file that you want to block from indexing.

header("X-Robots-Tag: noindex, nofollow", true);

Or, alternatively use the below piece of code.

header("X-Robots-Tag: noindex", true);

Block PDF directories through robots.txt

Simply add the below piece of code in your website’s robots.txt file. Make sure to replace /pdfs/ with your own directory name where your PDF files are there.

User-agent: *
Disallow: /pdfs/

Reviews & Ratings Get your stoe online with Shopify in 60 minutes Shop Now