1

I uploaded a large PDF file to a website (WordPress 4.5.4) and the engine automatically created a web address for it.

Of course, this page has no direct link from any of the website's pages, but I guess it could theoretically be discovered.

Can I upload a PDF so that it is only accessible via a direct link ( [...]wp-content/uploads/[...]uploaded_file.pdf)? So that only a person knowing the link can download it?

  • 1
    Upload pdf using ftp! – Rohit Kishore Sep 26 '16 at 12:17
  • @RohitKishore - dhanyavaad, I'll read up on the use of ftp with WP – CopperKettle Sep 26 '16 at 12:20
  • 1
    All ftp work as same. There is nothing new in wordpress ftp . And also "mera-saubhagya" – Rohit Kishore Sep 26 '16 at 12:30
  • Can you explain what's wrong with your uploaded pdf ? Normally if you don't share your pdf link ( that WP generate automatically for your pdf ) , then how can anyone will know your pdf url ?, So if some one know the link then that person able to view or download it.. But you just have to prevent direct file access in your wp-content or uploads directory. – Mohammad Limon Sep 26 '16 at 12:40
  • @mlbd - would it not be possible for someone to scan the website by just going through all the urls and thus find the url with the link to the PDF? I have very little knowledge in this area. If it is impossible or very hard to just stumble across this url, then it's okay with me. – CopperKettle Sep 26 '16 at 12:43
1

After uploaded your pdf file just do some step to hide pdf or uploads folder files that no one view those files except direct link.

To do that:

# Disable Directory Browsing simply add this small piece of code to your .htaccess file

Options All -Indexes

Or you can also block wp-content/uploads and specific pdf files from any user or viewer by adding this.

# Block files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/uploads/ - [F,L]
RewriteRule !^wp-content/ - [S=3]
RewriteRule ^wp-content/[^/]+\.pdf$ - [F,L]
</IfModule>

Note: to ensure the code below is not overwritten by WordPress, place it outside the # BEGIN WordPress and # END WordPress tags in the .htaccess file. WordPress can overwrite anything between these tags.

More info

# Hide Attachment files in WordPress search result. Now If you want to hide this pdf from your site search result or some other pdf as well then try this one.

// Exclude attachment from search results - WordPress
add_action( 'init', 'exclude_attachment_from_search_results' );
function exclude_attachment_from_search_results() {
    global $wp_post_types;
    $wp_post_types['attachment']->exclude_from_search = true;
}

This will help you hide all media files in WordPress search result.

# Disallow search engine to index pdf files Last you have to disallow search engine to not index your sites pdf files. Paste this code on .httaccess

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

More Info

Or use this code on your robot.txt

User-agent: *
Disallow: /pdfs/ # Block the /pdfs/directory.
Disallow: *.pdf  # Block pdf files. Non-standard but works for major search engines.

Hope it's help. and if you still fill confused how to do this then I'm suggest you better take help from someone who can do that for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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