Password Protection, .htaccess and ErrorDocument Commands

Big on Hosting. Unlimited Space & Unlimited Bandwidth

Hey guys,

This has frustrated me to no end for a few weeks so I thought I’d post here just in case someone else needs the help!

I moved accounts from one server to another, and ever since doing it, when I use the Password Protection inside cPanel to protect the public_html folder, it wouldn’t work 100%. The password prompt would not come up, but the page would show the HTML for the site, just no CSS styling. Certainly not secure! 🙂

After talking with the hosting company, they told me that I couldn’t password protect the public_html folder, only subfolders… welllll.. that’s not true as I’ve been doing it for 15 years and various servers!

This really caused issues with WordPress and the RewriteRule

Code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


Essentially the "RewriteRule . /index.php [L]" would fail as it wanted to be "RewriteRule ./ /index.php [L]"

Of course, if you make ANY update in WordPress to the settings, permalinks or even the sitename, it resets this section of code in the .htaccess file (anything between the BEGIN/END WordPress segments).

I finally found the issue – ErrorDocument

The server that I moved to did not have a 401 defined, thus the password would not protect.

To resolve it, I added "ErrorDocument 401 default" to the top of the .htaccess file and everything popped up and worked.

To resolve this on the server level, I created an .htaccess file for the /home folder, and this now works for every client, and still allows them to create their own ErrorDocument if they wanted.

I believe this can also be set under an Apache file loading the server, but this at least allowed me to get back to work in a fairly quick manner.

Do you have a better way to implement the ErrorDocument 401 definition?

Source

Both comments and pings are currently closed.

Comments are closed.