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


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/?$ [L,R=301]

I expect to allow logged-in users to redirect to 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 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 :”’”’ : ”’//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 

    //user has valid WP login session
    header('Location: {location of perl script}');
    //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?

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

Leave an answer