Background of my problem: I'd like to mask external download links as internal links and to be only accessible by logged-in wp users at htaccess level or with PHP script but when redirection happens the visitor outside of wordpress can still access download links by pasting direct url into browser bar.
I've tried this code for redirection to external link.
Redirect 301 /resources https://external.com/direct-download-link1
Before accessing that direct download link (ourwebsite.com/resources) a script must be like man in the middle and check if the visitor is logged into wordpress.
I'd like to change where the redirect goes have it go to a PHP page where you may load WordPress and check the role of the user to make sure they are logged in.
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
The above code can be developed with a simple php checking script. But don't know how to implement and which code to change.
https://external.com/direct-download-link1
into the browser and successfully downloading, or trying to stop someone typing your redirect URL into the browser and being redirected?