Connecting Tech Pros Worldwide Forums | Help | Site Map

.htaccess redirects according to user/pw combination?

Newbie
 
Join Date: Mar 2009
Posts: 1
#1: Mar 23 '09
Hi all,

I need to set up an .htaccess file in a root folder that requires a username and a password, and will direct the user to a different folder depending on the username and password entered.

E.g.:
  1. The user goes to www.example.com/
  2. They enter their username (bobsmith) and password (923r9w8c2w)
  3. They are redirected to www.example.com/bobsfolder/
  4. If a user goes to www.example.com/bobsfolder/ directly, they are prompted for a user name and password BUT do not have to re-enter it if they have already.

This is so that I can have multiple folders and multiple users, but only need to provide them with one common link.

Does anyone know if and how this can this be done? Thanks for reading this.

prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#2: May 10 '09

re: .htaccess redirects according to user/pw combination?


1. use session to carry the logged in user details.
2. when user logged in true then put username and other details assigned with session variables

3. check with session all the time when page start.

4. if the user is not logged in then session is empty and then should redirect to the login page otherwise, identify with the session user and give access to the page they have permission to.

dont knw what language you are using, so have different way to use session for user identification but same logic.


hope that might help you....
Reply

Tags
apache, htaccess, htpasswd, redirect, security