我正在尝试阻止我的直接pdf网址,但是很遗憾,我的pdf可以直接从该网址访问。我已经编辑了我的htaccess文件,该文件存储在/opt/bitnami/apps/wordpress/htdocs
我的pfds存储在/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
答案 0 :(得分:0)
您可以在.htaccess文件中使用以下代码来阻止从URL进行目录访问。
Options -Indexes
答案 1 :(得分:0)
Bitnami工程师在这里。我们的主要目标之一是以最安全的方式配置Bitnami应用程序。因此,我们将.htaccess文件中的配置移到了主应用程序配置文件中,并默认将AllowOverride选项设置为None。
.htaccess文件的内容已移至/opt/bitnami/apps/wordpress/conf/htaccess.conf文件。如果您想添加新信息,请按照以下步骤操作
注意:.htaccess文件的内容在这里是占位符,将其替换为插件创建的/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/securepdfs/.htaccess文件的内容。
...
<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/securepdfs">
CONTENT OF THE .htaccess FILE HERE
</Directory>
sudo /opt/bitnami/ctlscript.sh restart
您可以在我们的文档中找到更多信息:https://docs.bitnami.com/aws/apps/wordpress/administration/use-htaccess/