【发布时间】:2019-05-27 17:19:56
【问题描述】:
我正在尝试阻止我的直接 pdf 网址,但不幸的是,我的 pdf 可以直接从该网址访问。我已经编辑了我的 htaccess 文件,该文件存储在 /opt/bitnami/apps/wordpress/htdocs
我的 pfd 存储在/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/securepdfs
我浏览了这些网址:
RewriteCond %{REQUEST_FILENAME} ^.*(pdf)$
RewriteRule ^(.*)$ /wp-content/download.php?file=$1 [L]
require_once('/path/to/wp-config.php');
require_once('/path/to/wp-includes/wp-db.php');
require_once('/path/to/wp-includes/pluggable.php');
if (!is_user_logged_in()) {
// redirect to login page or show the message + login form
die; // or exit, wp_redirect etc
}
header("Content-Type: application/octet-stream");
$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp); ```
All pdfs urls are public accessible
https://abc/wp-content/uploads/securepdfs/2019/05/Testing-pdf-1.pdf
【问题讨论】:
-
你重启了apache吗?
-
是的,我正在使用 aws 服务器
-
尝试使用 .htaccess 。这是一个例子stackoverflow.com/questions/11728976/…
-
我用的是apache 2.4.33 版本有问题吗?
-
应该没有问题。
标签: wordpress amazon-web-services amazon-s3 amazon-ec2 bitnami