我最近也希望如此,只是我只想确保发票的安全。
我把这个放在的WordPress部分上面。htaccess
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*wp-content/uploads/invoices/.*
RewriteRule ^wp-content/uploads/(invoices/.*)$ read-file.php?file=$1 [QSA,L]
</ifmodule>
这将重定向所有想要转到invoices目录中的文件以读取文件的人。php wich也位于WordPress的顶层。读取文件。php有以下代码来检查用户是否登录
<?php
// Load wp
require_once(\'wp-load.php\');
// If user is logged in
if( ! is_user_logged_in() ) {
// Redirect to home
wp_redirect( url to your login page );
exit;
}
// Additional checks here
// Headers to open or download the file
// readfile( $file );
// exit;
希望有帮助!