0

一般来说,问题是:如何将外部下载链接屏蔽为内部链接,并且只能由登录的 wp 用户在 htaccess 级别或使用 PHP 脚本访问?我们的外部 URL 有基于 Perl 的脚本,它会生成不同的下载 URL。如果您帮助我们如何在外部网站上应用它,我们可以这样做。

www.ourwebsite.com/resources我们通过简单的 htaccess 代码成功重定向到外部下载链接:

Redirect 301 /resources https://external.com/direct-download-link1

但是,如果 URL(www.ourwebsite.com/resources/download-1.html 等)被 WordPress 会员抓取并在他们未登录时分享并粘贴到他们的浏览器地址栏中,则仍然可以访问下载链接. 我们想阻止它。那么如何禁止非会员直接访问下载链接呢?

4

1 回答 1

0

如果您可以更改重定向的位置,请将其转到 PHP 页面,您可以在其中加载 WordPress 并检查用户的角色以确保他们已登录。

require('../wp-load.php');  // modify to reflect where your PHP file is in relation to Wordpress
$roles = wp_get_current_user()->roles;  // get current users role

if (!in_array('alloweduserrole',$roles)) {  // modify to match your roles that are allowed to download

    header('Location: http://www.ourwebsite.com/');
    exit;

}  // end of if user does not have the proper role
于 2019-05-14T12:43:49.603 回答