仅在WordPress上登录的成员才能访问如何使HTACCESS重定向的下载URL访问



通常,问题是:如何掩盖外部下载链接作为内部链接,并且只能通过HTACCESS级别或使用PHP脚本来登录WP用户才能访问?我们的外部URL上有基于Perl的脚本及其生成不同的下载URL。如果您有助于我们如何将其应用于外部站点,我们可以这样做。

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

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

但是,如果WordPress成员刮擦URL(www.ourwebsite.com/resources/resources/download-1.html等(并共享&将其粘贴到他们的浏览器地址栏中时,当他们不登录时,下载链接仍然可以访问。我们想防止它。那么如何禁止非会员直接访问下载链接?

如果您可以更改重定向的位置,请转到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

最新更新