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

Discussion in 'Community Discussion' started by Ahheck01, Mar 24, 2012.

  1. Ahheck01 macrumors 6502

    Joined:
    Aug 7, 2006
    #1
    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!!
     
  2. waloshin macrumors 68040

    waloshin

    Joined:
    Oct 9, 2008
    #2
    Password protect the directories through your Cpanel.
     
  3. Ahheck01 thread starter macrumors 6502

    Joined:
    Aug 7, 2006
    #3
    Like I said, I can already do that. I just can't get one URL to redirect to different URLs based on what login is entered.
     
  4. r1ch4rd macrumors 6502a

    r1ch4rd

    Joined:
    Aug 5, 2005
    Location:
    Manchester UK
    #4
    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>
    
     
  5. Ahheck01 thread starter macrumors 6502

    Joined:
    Aug 7, 2006
    #5
    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!
     
  6. r1ch4rd macrumors 6502a

    r1ch4rd

    Joined:
    Aug 5, 2005
    Location:
    Manchester UK
    #6
    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.
     
  7. Ahheck01 thread starter macrumors 6502

    Joined:
    Aug 7, 2006
    #7
    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?
     
  8. r1ch4rd macrumors 6502a

    r1ch4rd

    Joined:
    Aug 5, 2005
    Location:
    Manchester UK
    #8
    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?
     

Share This Page