Jon Hendershot
Jon Hendershot

Reputation: 476

Exclude directory from wordpress rewrite issue

In /public_html/ I have a wordpress install as well as a directory - 'mydirectory' - that I'd like to protect and be able to access directly. I've got the protection setup with an .htaccess and .htpasswd file, but I'm only getting 404 errors when I try to access the files in that folder. I've tried just about every re-write option I can find for the root level .htaccess file, but nothing has worked. I'm curious if I'm missing something outside of the rewrite condition that could be affecting it? I cannot seem to figure out why I can't get this to work! Below are my various .htaccess files and the rewrites i've tried.

Root Level:

# 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

.htaccess in mydirectory:

ErrorDocument 401 default

AuthType Basic
AuthName "LampreyTrillo"
AuthUserFile file:///public_html/mydirectory/.htpasswd
Require valid-user

.htpasswd in mydirectory:

test:pass

Rewrites I've Tried:

RewriteRule ^mydirectory(/.*)?$ - [L,NC]

# disable the rewrite engine in the ignored directory .htaccess
RewriteEngine off 

RewriteCond %{REQUEST_URI} ^/mydirectory/(.*)$

RewriteCond %{REQUEST_URI}  !(mydirectory) [NC]

#Change last rewrite rule from '. /index.php' to './ /index.php'

RewriteRule ^mydirectory/.*$ - [PT]

RewriteCond %{REQUEST_URI} !^/(mydirectory|mydirectory/.*)$ 

I'm stumped, cant figure out what I'm missing here so any advice or new information would be greatly appreciated! Thank you in advance!

Upvotes: 0

Views: 1335

Answers (1)

Evan Rose
Evan Rose

Reputation: 104

Add this to your .htaccess file:

RewriteCond %{REQUEST_URI}  !(your_excluded_directory|your_excluded_directory_2|your_excluded_directory_3_etc) [NC]

just before

RewriteCond %{REQUEST_FILENAME} !-f

Upvotes: 3

Related Questions