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

by diladadufe   Last Updated May 17, 2019 07:08 AM

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?



Related Questions


Redirect to homepage if attmpting to leave intranet

Updated October 28, 2017 17:08 PM




PHP - redirect https to http and www to non-www

Updated November 20, 2017 18:08 PM