【问题标题】:Cannot prevent a file from direct URL Access in wordpress无法阻止文件在 wordpress 中直接 URL 访问
【发布时间】: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


【解决方案1】:

您可以在 .htaccess 文件中使用以下代码来阻止来自 URL 的目录访问。

Options -Indexes

【讨论】:

    【解决方案2】:

    Bitnami 工程师在这里。我们的主要目标之一是以最安全的方式配置 Bitnami 应用程序。为此,我们将 .htaccess 文件中的配置移至主应用程序配置文件中,并将 AllowOverride 选项默认设置为 None。

    .htaccess 文件的内容已移至 /opt/bitnami/apps/wordpress/conf/htaccess.conf 文件。如果您想添加新信息,请按照以下步骤操作

    • 在 /opt/bitnami/apps/wordpress/conf/htaccess.conf 文件中添加一个新条目,指定 htaccess 文件所在的路径 (/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/ securepdfs) 并粘贴到该文件的内容下方。

    注意:此处的 .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>
    
    • 重启 Apache 以使更改生效:
    sudo /opt/bitnami/ctlscript.sh restart
    

    您可以在我们的文档中找到更多信息:https://docs.bitnami.com/aws/apps/wordpress/administration/use-htaccess/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      • 2012-11-03
      • 2013-04-02
      相关资源
      最近更新 更多