Jump to content

Password Protect Sub Directory - htaccess


ianitm

Recommended Posts

Hi,

 

I am running a social networking site that allows a usersname to be entered after the website url for quick access to their profile. I need to have a htaccess file on the root of the server to exlcude certain subdirectories from being percieved as a username - like forums etc.

 

I would like to set up another exculded directory called ebooks (mysite.com/ebooks) which will be password protected. At the moment I have a htaccess file in this subdirectory which is atempting to password protect the folder but I believe the root htaccess is causing an authorization error before the user is even asked for a password.

 

My root htaccess looks like this:

 

RewriteEngine On

ErrorDocument 403 /index.php?do=/public/error/403/
ErrorDocument 404 /index.php?do=/public/error/404/

RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/.smileys/.*
RewriteCond %{REQUEST_URI} !^/cgi-bin/.*
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/forums/.*
RewriteCond %{REQUEST_URI} !^/ebook/.*
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/sitemap.xml$
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteRule ^index.php(/.*)$ /index.php?do=$1 [L]

RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/cgi-bin/.*
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/forums/.*
RewriteCond %{REQUEST_URI} !^/ebook/.*
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/sitemap.xml$
RewriteRule ^(.*)$ /index.php?do=/$1 [L]

 

and the htaccess in the ebooks subdirectory, like this:

 

AuthUserFile /home/***/public_html/ebook/.htpasswd
AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>

 

Could anybody please explain why this is giving me a 401 when navigating to the ebooks folder and not requesting the username and password?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/126619-password-protect-sub-directory-htaccess/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.