增强wordpress的安全性,以直接访问文件夹


enhance the wordpress security to access directly folder

一旦我将新图像上传到wordpress, new directory将在每月更改(like in aug /var/www/mysite/wp-content/uploads/2015/08)时创建。它不包含index。php文件所以每个知道wordpress目录结构的人都可以直接访问这个文件夹。所以我想做的是创建一个index.php文件一旦新的上传目录创建。所以我可以给wordpress更好的安全性。非常感谢您的帮助

我以前遇到过这样的问题,我使用wordpress过滤器upload_dir来修复它。

请将此代码添加到您的function.php文件中,并在您的媒体中上传图像。

add_filter('upload_dir', 'sofg_secure_dir');
function sofg_secure_dir( $param ){ 
   $filename = $param['path'].'/index.php';
    if (!file_exists($filename)) {
            $myfile = fopen($filename, "w") or die("Unable to open file!");
            $txt = "<?php // silence is golden  ?>";
            fwrite($myfile, $txt);
            fclose($myfile);
    }
    return $param; 
}

你需要使用。htaccess禁用目录索引

/var/www/mysite/wp-content/中创建新文件.htaccess

在现有的.htaccess文件中添加以下行。

Options -Indexes