3

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
</Files>     

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

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?

amb9800
  • 31
  • 2
  • 2
  • 3
  • 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 07 '10 at 03: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 07 '10 at 03:16

1 Answers1

1

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.

matthew
  • 1,309
  • 1
  • 11
  • 21
  • 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 06 '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 07 '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 08 '10 at 11:52