简体   繁体   English

如何防止PDF文件在Wordpress中直接访问URL?

[英]How to prevent a PDF file from direct URL Access in Wordpress?

In my website i have storing user resume in Wordpress upload folder. 在我的网站上,我将用户简历存储在Wordpress上传文件夹中。 I have created sub folder resumeuploads under the wordpress wp-content/uploads/ folder. 我已经在wordpress wp-content / uploads /文件夹下创建了子文件夹resumeuploads Now the resume are storing on the resumeuploads folder by using PHP code. 现在,使用PHP代码将简历存储在resumeuploads文件夹中。 Now i want to restrict the public access of PDF files on my website. 现在,我想限制我网站上PDF文件的公共访问。 If enter the http://www.example.com/wp-content/uploads/resumeuploads/my.pdf link on browser i can access the PDF files now i want to restrict that direct access. 如果在浏览器上输入http://www.example.com/wp-content/uploads/resumeuploads/my.pdf链接,我现在可以访问PDF文件,我想限制直接访问。 I have tried below code in htaccess but its not working for me. 我已经尝试过htaccess中的以下代码,但是它对我不起作用。 Could you please help me to solve the issue . 你能帮我解决一下这个问题吗?

Code 1 代码1

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|pdf)$ - [F]

Code 2 代码2

RewriteCond %{REQUEST_URI} \.(pdf|zip)$ [NC]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]

Or is there any way to redirect when accessing the pdf file url into home page??? 还是在访问pdf文件URL到主页时有任何重定向的方法???

If you want to deny access to all pdf files in the folder, try this in .htaccess: 如果要拒绝访问该文件夹中的所有pdf文件,请在.htaccess中尝试:

# Deny access to files with extensions .pdf
<FilesMatch "\.(pdf)$">
Order allow,deny
Deny from all

</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM