...

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

dharvell
01-16-2009, 12:51 AM
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.

dharvell
01-16-2009, 06:21 PM
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:

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:

<?
$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! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum