How to allow download url redirection only if user logged in WordPress site?

Question

I’m trying to allow url-redirection (from /dl urls) only if user is logged-in to wordpress site. Otherwise don’t allow. However it went “page not found” when i click these urls with or without logging in.

I’ve used this .htaccess code on public-html level:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} ^.*wordpress_logged_in.*$ [NC]
RewriteRule ^dl/?$ https://external.com/directdownload- [L,R=301]

I expect to allow logged-in users to redirect to https://external.com/directdownload- links and don’t allow redirection (and redirect them to login page) if they are not logged-in to wordpress. However when i click the links which are like https://www.example.com/dl/23434234/link.html both logged-in and not logged-in goes to “page not found”. How to fix?

also tried below code and get the same file code when i click :”’www.example.com/download.php/2n234n23/file.html”’ : ”’//load WP without theme support or hooks etc. define('WP_USE_THEMES', false);”’

//load WP without theme support or hooks etc.
define('WP_USE_THEMES', false);
require('./wp-load.php'); //location of this file may be different 

if(get_current_user_id()){
    //user has valid WP login session
    header('Location: {location of perl script}');
}else{
    //user is not logged in
    header('Location: {location to boot them to}');
}
exit; //just because

How can i change above code to make it useful?

0
, , , , diladadufe 1 year 2020-07-20T13:11:24-05:00 0 Answers 57 views 0

Leave an answer

Browse
Browse