Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I used to serve PDF files as static file:

http://domain.com/pdf/file1.pdf

and PDF files perfectly indexed by Google and other search engines. Then I decided to change my structure to place pdf files outside public folder, and then make them downloadable through PHP as

http://domain.com/pdf.php?id=1

The PDF files with the new structure have not been indexed by search engines.

From SEO point of view, is it better to serve PDF files as static files, rather than making them downloadable through a PHP script?

The script looks like

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
share|improve this question

1 Answer 1

up vote 1 down vote accepted

According to http://stackoverflow.com/questions/312230/proper-mime-media-type-for-pdf-files the proper mime type for PDF files is application/pdf so you should change the line in your script to:

header('Content-Type: application/pdf');

I suspect that Google also uses the file extension on the URL as an indicator that there is a PDF file there and that it should be indexed. You should consider serving your PDF files like:

http://domain.com/pdf.php/filename.pdf

You wouldn't even need a rewrite rule to do so, you could get the filename in PHP out of the $_SERVER[REQUEST_URI] variable.

share|improve this answer
    
I am sure that Google checks the headers of any links it finds online, regardless of whether it's a known "extension" or not. –  DisgruntledGoat Aug 3 '13 at 18:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.