Personal Website - Set Different Logins to Redirect to Different Directories?

Ahheck01

macrumors 6502
Original poster
Aug 7, 2006
443
35
Hey all, just wondering if anyone out there's pretty good with web development.

I've got three different groups of people that will be coming to my website, and I'll be giving each group their own login. I'd like people to be able to go to the main domain, and based on what login they put in, it redirects to their specific directory. For example:

They go to:
www.mydomain.com

They're prompted for a username and password. They type in:

username: group1
password: password

Their browser then jumps to www.mydomain.com/group1/

If at the main domain they type in username group 2, they're taken to mydomain.com/group2/

Anyone know how I might do that? I can do password production through my dreamhost panel, but I can automatically redirect based on the login.

Would hugely appreciate any help!!
 

waloshin

macrumors 68040
Oct 9, 2008
3,171
66
Hey all, just wondering if anyone out there's pretty good with web development.

I've got three different groups of people that will be coming to my website, and I'll be giving each group their own login. I'd like people to be able to go to the main domain, and based on what login they put in, it redirects to their specific directory. For example:

They go to:
www.mydomain.com

They're prompted for a username and password. They type in:

username: group1
password: password

Their browser then jumps to www.mydomain.com/group1/

If at the main domain they type in username group 2, they're taken to mydomain.com/group2/

Anyone know how I might do that? I can do password production through my dreamhost panel, but I can automatically redirect based on the login.

Would hugely appreciate any help!!
Password protect the directories through your Cpanel.
 

r1ch4rd

macrumors 6502a
Aug 5, 2005
980
1
Manchester UK
How are you taking their username/password? Using .htaccess (or similar) or through a form on a webpage?

If you are using .htaccess then you can set up a simple index.php containing the following

Code:
<?php
   
   $folder = $_SERVER[REMOTE_USER];

   header("Location: http://www.your-domain.com/members/$folder/");
  
?>
If using a form on the webpage, you need to put something similar in your authentication step (that will depend on what language you are using).

This may work if you don't want to use php

Code:
<html>
<meta http-equiv="refresh" content="0;url=http://www.web-address.com/members_folder/<!--#echo var="remote_user" -->/">
</html>
 

Ahheck01

macrumors 6502
Original poster
Aug 7, 2006
443
35
How are you taking their username/password? Using .htaccess (or similar) or through a form on a webpage?

If you are using .htaccess then you can set up a simple index.php containing the following

Code:
<?php
   
   $folder = $_SERVER[REMOTE_USER];

   header("Location: http://www.your-domain.com/members/$folder/");
  
?>
If using a form on the webpage, you need to put something similar in your authentication step (that will depend on what language you are using).

This may work if you don't want to use php

Code:
<html>
<meta http-equiv="refresh" content="0;url=http://www.web-address.com/members_folder/<!--#echo var="remote_user" -->/">
</html>
Right now I'm using the control panel from dreamhost to apply a .htaccess username and password to a directory. If you go to a URL, a prompt comes up for username and password.

So based on the code you suggested, what part of it tells specific logins to go to specific places?

Thanks!
 

r1ch4rd

macrumors 6502a
Aug 5, 2005
980
1
Manchester UK
In that case, you just need to create a index.php file containing the following

Code:
<?php
   
   $folder = $_SERVER[REMOTE_USER];

   header("Location: http://www.your-domain.com/members/$folder/");
  
?>
With PHP you can read some standard variables from either the server or the users PC. In this case we want to read the username for the person logged in from the server. That's what the first line does. This is stored as the $folder variable.

The second line concatenates that username with your URL (you will have to change the exact URL for your particular setup). Setting the location like this causes a redirect.

This assumes your web server supports PHP.
 

Ahheck01

macrumors 6502
Original poster
Aug 7, 2006
443
35
In that case, you just need to create a index.php file containing the following

Code:
<?php
   
   $folder = $_SERVER[REMOTE_USER];

   header("Location: http://www.your-domain.com/members/$folder/");
  
?>
With PHP you can read some standard variables from either the server or the users PC. In this case we want to read the username for the person logged in from the server. That's what the first line does. This is stored as the $folder variable.

The second line concatenates that username with your URL (you will have to change the exact URL for your particular setup). Setting the location like this causes a redirect.

This assumes your web server supports PHP.
Forgive my naivety, though I think I'm beginning to understand.

So for this to work, the specified directory would need to contain the username of the person logging in, correct?

So if the username and password I setup with .htaccess is "fred" and "password", that code you just posted would assign that username to the $folder variable, and would take me to http://www.your-domain.com/members/fred/

Am I following this correctly?
 

r1ch4rd

macrumors 6502a
Aug 5, 2005
980
1
Manchester UK
Exactly!

Does that do what you need, or do you want to direct multiple users to the same directory? ie. do fred and george go to yourwebsite.com/group1 and mary and jane go to yourwebsite.com/group2?