1

My htaccess file, below, works fine on my local development server (AMPPS on Mac) but not on my live server (which is through Cloudways).

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# BEGIN THIS DL-FILE.PHP ADDITION
RewriteCond %{REQUEST_URI} ^.*wp-content/.*
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
# END THIS DL-FILE.PHP ADDITION

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Options -Indexes

In both local and live environments, this is in the root directory of a fresh WordPress install.

On local, when I try to access test.jpg in /wp-content/uploads/, I am redirected to the login page if not already logged in, which is the intended behavior. This, of course, assumes the presence of the referenced dl-file.php. But even without the referenced file present, I get a 'not found' error for that file. The same cannot be said for my live server, which simply loads the image as if the htaccess file was not even present.

What I am trying to accomplish is outlined in the following article:

https://docs.wpo365.com/article/15-restricing-access-to-wp-content-to-authenticted-users-only

What am I missing here?

3
  • The only change from the default WP htaccess file is the addition of the two middle lines. It's almost as if the server isn't recognizing the htaccess file when trying to load the image directly at domain.com/wp-content/uploads/test.jpg because forcefully breaking the htaccess file returns an internal server error when trying to load the image on local but not on live (whereas the root domain shows said error on live when forcefully breaking the htaccess file). Jan 30 '20 at 21:26
  • Are there any other .htaccess files along the filesystem path (as these could override the parent .htaccess file)? (Aside: You should avoid editing code inside the # BEGIN WordPress code block since WP will try to overwrite this when it updates. Also the RewriteCond directive before the rule you added is entirely superfluous.)
    – MrWhite
    Jan 30 '20 at 21:34
  • There may be an issue with your http server configuration. If you're using Apache, the 'AllowOverride' needs to be enabled otherwise your server ignore .htaccess files. Also, the server must allow rewrite (mod_rewrite or similar). Just a thought. Jan 31 '20 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.