Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.