Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have WordPress installed in my root directory, for which a RewriteRule is in place.

I need to password-protect a subfolder ("blue"), so I set the htaccess in that folder as such.

Problem is that the root htaccess RewriteRule is applying to "blue" and thus I get a 404 in the main WordPress site (instead of opening the password dialog for the subfolder).

Here's the root htaccess:

RewriteEngine on

<Files 403.shtml>
order allow,deny
allow from all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I tried inserting this as the second line, to no avail:

RewriteRule ^(blue)($|/) - [L]

Also tried inserting this before the index.php RewriteRule:

RewriteCond %{REQUEST_URI} !^/blue/

That didn't work either.

Also inserted this into the subfolder's htaccess, which didn't work either:

<IfModule mod_rewrite.c> RewriteEngine off </IfModule>

Any ideas?

share|improve this question
I was talking in the #httpd chat another day and ($|/) does not seem to fit the idea so it should be: RewriteRule ^(blue$|blue/) - [L] I also tried some stuff later after it and it seems to be the case. Also make sure you put this rule at the at the begin and not after your other rules so it takes places as soon as it hits – Prix Oct 7 '10 at 3:14
In ragards to the .htaccess, if you have one at a top level directory, it will overwrite any others. For example, root directory is /home/domain/public_html and there you have a .htaccess then you have /home/domain/public_html/forum with another .htaccess the later would be ignored. – Prix Oct 7 '10 at 3:16

Try dropping the leading / from the RewriteCond

RewriteCond %{REQUEST_URI} !^blue/

EDIT: It should work without the RewriteCond as the first two conditions should cover it unless you're doing more rewrites in that directory or something.

Are you using custom error pages? Something is changing the Request_URI so that it no longer matches any of the conditions.

If you're not on a shared host or if your host supports it try setting up a rewrite log this will tell you exactly what is going on.

share|improve this answer
So I played around a bit-- when no password is set in the subfolder's htaccess, the folder works properly (even without the RewriteCond added to the root htaccess). But when the password is there, it seems to go through the RewriteRule in the root htaccess and gives the 404 (even with the leading slash removed). Here's what I have in the subfolder htaccess: AuthType Basic AuthName "BlueFolder" AuthUserFile "/home/user/.htpasswds/public_html/blue/passwd" require valid-user – amb9800 Jul 6 '10 at 17:03
Well it's showing a 404 within WordPress (e.g. the WP site in the root shows a 404 message in the center), meaning the RewriteRule is being applied and it's hitting WP's index.php, which serves a 404. – amb9800 Jul 7 '10 at 17:51
Correct: It appears that it goes through the root .htaccess fine, then hits the /blue .htaccess and gets rewritten, then when it gets passed through the root .htaccess a second time it no longer gets excluded by the RewriteCond and thus gets rewritten to the WP index.php... or at least that's what I'm guessing is happening. – matthew Jul 8 '10 at 11:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.