Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    66
    Thanks
    7
    Thanked 0 Times in 0 Posts

    New To .htaccess - About Ready To Jump Off Highest Building...

    As the title states, I'm a complete n00b when it comes to .htaccess. This is the first time I'm trying to do something with .htaccess and I'm as lost as possible.

    What I'm trying to do is simple, in theory. I want to take what a user would type:

    http://www.mydomain.com/username

    and redirect to the actual address:

    http://www.mydomain.com/profiles/username/profile.php

    I've read about every online tutorial there is and I understand absolutely zero of it (because they are not written for us .htaccess virgins in mind).

    If somebody can help me with this, I would be forever grateful.

    Thank you in advance.

    +dharvell

    PS - my host is GoDaddy who has mod_rewrite enabled by default.

  • #2
    New Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    66
    Thanks
    7
    Thanked 0 Times in 0 Posts
    After 2 lost days of experimenting, I think I found a solution. It's a duct tape and glue solution, I think, but it works.

    What I did was stumble across an .htaccess list that didn't kill my server. Then, created a PHP file to handle the rest.

    .htaccess:

    Code:
    RewriteEngine on
    Options +FollowSymlinks
    
    RewriteRule ^([A-Za-z0-9-]+)/?$ http://www.domain.com/profile.php?user=$1 [L]
    Then, a PHP file handles the rest:

    PHP Code:
    <?
    $theUser 
    $_REQUEST['user'];
    $getUser mysql_query("SELECT * FROM users WHERE userName='" .$theUser"' LIMIT 1") or die(mysql_error());

    if(
    $userRow mysql_fetch_array($getUser))
    {
        do
        {
            
    header("location: ../profiles/" .$theUser"/profile.php");
        }
        while(
    $userRow mysql_fetch_array($getUser));
    }
    else
    {
        
    header("location: ../errorHandlePage.php");
    }
    mysql_close();
    ?>
    This seems to work pretty well. If the visitor to my website enters domain.com/username where "username" is a valid user, they are redirected to the appropriate profile page. If "username" is invalid, they are directed to a graceful error handler where they are able to search through the users to find who they are looking for (if they even exist on the site).

    It's a cobbled solution, but by golly it works!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •