Problem
- SubDir under WordPress / Web App : Sub directories under your WordPress installation used for other stuff are redirected to WordPress.
- Password Protected SubDir under WordPress / Web App : Some commonly thought out solutions for problem will not work where your subdir is password protected by .htaccess
Problem/Solution (1) Explained
When you want to use clean SEO friendly URLs for WordPress (or any other web application for that matter) you can use mod_rewrite to achieve clean URLs.
This is achieved by redirecting (actually rewriting) every request to one single point of entry (commonly index.php).
However using this method means that if you have a sub-folder or an actual file eg. otherstuff / status.html, apache might think that this should be redirected to your web app as well.
Web applications get around this by adding conditions so that the rewrite only works when the actual file/folder does not exist.
Example, WordPress will write a rewrite following in .htaccess for you (or give you the code to write yourself if you do not have .htaccess writeable).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Bigger Problem (2)
A bigger problem is that you will lose some hair when trying to think why this simple trick endorsed by WordPressdoes not work with password protected directories with htaccess files of their own.
For the password protected directories to work apache needs to throw a “401 Unauthorized” header and server an error file. On the other hand the idea for mod_rewrite is that it will not throw 404 error (or a 401 error) and pretend that the missing file (or protected file) exists.
The Solution (2)
Add one of the following lines to your .htaccess in password protected directory.
ErrorDocument 401 default
(throws default 401 error)
ErrorDocument 401 "Unauthorised"
(throws 401 error with string Unauthorised (yes I am British))
ErrorDocument 401 /401.php
(throws 401 error with PHP file /401.php in root (yes I prefer PHP))