Error 404 when viewing a page protected with a .htpasswd file

Problem

When you attempt to view a page that is located within a CMS (Drupal, WordPress, Joomla, etc) site folder and uses a .htpasswd file, you are redirected to the site’s 404 error page.

Cause

When authentication is needed, it may be searching for a files on the server with the name “401.shtml” or similar. This request is instead handled by the CMS and results in a 404 (not found) error.

Solution

This has been tested with Drupal but should work for other Content Management Systems.

  1. Open the site’s .htaccess file for editing.
  2. Look for the following lines of code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
  3.  Change it to the following:
    RewriteCond %{REQUEST_FILENAME} !\.shtml$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
  4. Save the updated file to the server.

1 comment

  1. THANK YOU. I was trying to create a secured folder outside of my wordpress installation using htaccess, but everytime I tried to access the secured portions, I’d get redirected to 404. This solved my problem perfectly. Thanks!!

Leave a comment

Your email address will not be published. Required fields are marked *