Forum Moderators: phranque

Message Too Old, No Replies

.htaccess username redirects

.htaccess username redirects

         

shanewebber

5:47 am on Dec 20, 2009 (gmt 0)

10+ Year Member



I want to be able to create the .htaccess that will allow individual user redirection.

So, in other words. Redirection based on the user that logs in via the login page.

From the main "MEMBERS" directory
If "USER1" enters the correct password then that user will redirected to "firstuser" directory.
If "USER2" enters the correct password then that user will be redirected to "seconduser" sub directory.

I currently have:

This is good to allow the same directory to be open to the 1 user, but i need mutple users, and multiple redirects.

AuthType Basic
AuthName "members"
AuthUserFile "/home/*******/.htpasswds/public_html/members/cgi-bin/members/passwd"
require valid-user

------------------------------------------

I need something like:

AuthType Basic
AuthUserFile "/home/*******/.htpasswds/public_html/members/cgi-bin/members/passwd"
AuthName "members"
require valid-user
satisfy any
#if it's user 'user1', do this
#Redirect /members/useraccounts/user1/
#if it's user 'user2', do this
#Redirect /members/useraccounts/user2/

and then so on for the rest of the other users.

Again:

- The Client hits a DIR using the login page with the .htaccess which asks for Username/Password
- Based on Username/Password, client is sent to a web page (with differing web pages for different clients)

Someone please help! I already have the login script in place ready to use when this is completed.

g1smd

8:27 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What if the user goes straight to that other address, will they be asked to log in?

shanewebber

8:34 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



no, they wouldnt need to login again

shanewebber

8:35 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



the htaccess file should protect the /members/ directory and any other sub-directories within this folder.

users should login and be redirected to there designated folder

g1smd

8:35 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What if they went there for the very first time, because someone had told them the URL?

shanewebber

9:18 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



i am not sure. that is why i need help with this problem. i basically want to be able to redirect the users that are able to login to their own directory. maybe i can have the redirected to a page in the directoy that is called something else other than index/default.shtml

if user gives out the url to connect to the url, then the user should see the index.shtml page where the page will redirect them to the login page back in the main directory? ?

shanewebber

9:21 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



ok maybe the directory thing is no the best idea, but then how would i create the htaccess to redirect e.g. user1 > user1.shtml and then user2 > user2.shtml

shanewebber

5:42 am on Dec 21, 2009 (gmt 0)

10+ Year Member



i have used the code for .htaccess login script in the html format for easy to use from the login page on my website. from here i would like to redirect my users individually. please can you help with this code below.

the code does not work, but must be something simple to do with this code to make it work rather than it just redirecting all users to the one page.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Username</title>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
if (username && "user1" && password && server) {
loggedin=true;
window.location="useraccounts/user1/page.shtml";
}
if (username && "user2" && password && server) {
loggedin=true;
window.location="useraccounts/user2/page.shtml";
var htsite = "http://" + username + ":" + password + "@" + server;
window.location = htsite;
}
else {
alert("Please enter your username and password.");
}
}
// End -->
</script>
</head>

<body>
<form name=login>
<input type="hidden" name="server" value="www.mydomain.com/members/cgi-bin/login/l08dsk9jhnd3/">
Username:
<input type=text name=username size=20>
<br><br>
Password:
<input type=password name=password size=20>
<input type=button value="Login!" onClick="Login(this.form)" name="button">
</form>
</body>

</html>

jdMorgan

4:50 pm on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is beyond basic Apache auth, but it strikes me that you need some method to 'remember' that the user is logged in. For this, I suggest that you set a client-side cookie after the user logs in, and then test that cookie to avoid 'looping' and repeatedly asking the user to log in again and again.

Jim