• Hi all,

    I have a .htaccess file in my public_html folder which is the root of a WOrdpress installation.

    Inside it I have this rule: RedirectMatch /wp-content/uploads/(.*)$ /dl-file.php?file=$1

    The content of dl-file (which is also in the root) is this:

    <?php
    require_once('wp-load.php');
    
    if (is_user_logged_in()){
    	echo "You are logged in";
    }else{
    	echo "not logged in";
    }

    This rule is working well for files that do not exist: If I directly access the non-existing file https://simnigeria.org/wp-content/uploads/13.png, I see the message:

    not logged in

    .
    If I however access a file that does exists, I see the file, while the result should be the same.

    why is that?

    • This topic was modified 5 years, 9 months ago by tsjippy.
    • This topic was modified 5 years, 9 months ago by tsjippy.
    • This topic was modified 5 years, 9 months ago by tsjippy.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Based on the code you pasted from dl-file.php it appears to be working as intended – displaying one message if you’re logged in and another if you’re not.

    If what you’re trying to achieve is to restrict access to your files for people who are not logged in, please see this blog post which explains how to do that: https://aftabablog.wordpress.com/2017/02/17/how-to-make-your-uploads-in-wordpress-visible-only-for-logged-in-users/

    Hope this helps!
    -Bjørnar

    Thread Starter tsjippy

    (@tsjippy)

    Thanks I tried that, does not work.

    But I started with a clean WordPress installation with this in my .htaccess:

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
    
    # BEGIN WordPress
    # The directives (lines) between <code>BEGIN WordPress</code> and <code>END WordPress</code> are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /test9/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /test9/index.php [L]
    </IfModule>
    
    # END WordPress

    I found that when I access a picture over http it works (I get blocked), but if I access the picture over https the rules do not work and I see the picture

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘.htacces file problem’ is closed to new replies.