Jump to content

username.webhost.com?


BelovedDoll

Recommended Posts

I wasn`t sure what programming language (if any) is used to create something like username.webhost.com with the registered users of my website? Currently they are kept in format of like webhost.com/profile.php?id=4574857 I would like to do something like username.webhost.com or some variation of that for my users to be able to show their profiles to their friends easier and make it easier for others to locate profiles. Words are much easier to remember than numbers. webhost.com/username/ is also acceptable. Whichever is going to work, or even better, if both would be possible?

 

So what would I need to accomplish something like this? Any advice or input would be great.

Link to comment
Share on other sites

The urls you're after are possible with the use of mod_rewrite.

 

However what mod_rewrite cant do is convert a users id into the corresponding userrname for you. You will have to modify your scripts so they output the urls you are wanting to use. Eg

<?php
$username = 'BelovedDoll';
echo "<a href=\"site.com/$username/\">See {$username}'s Profile</a>";
?>

 

You'd then use the following rule to map site.com/username/ to site.com/profile.php?user=username

RewriteEngine On
RewriteRule ^([a-z0-9_-]+)/?$ profile.php?user=$1 [NC,L]

Now in profile.php you'd use $_GET['user'] to get the username from the url.

 

Note: You will need to modify profile.php so it retrieves the users details from the database based on the username rather than the user id associated to that username. mod_rewrite doesn't have the ability to convert a username to the corresponding user id for you.

Link to comment
Share on other sites

  • 1 month later...

Ok, I have been reading over things about mod_rewrite and reading on permalinks. It sounds like that I would have to edit my htaccess file for each and every submission made and users join my site. But I`m only finding information on doing manual rewrites, which is definitely not the way to go. I tried looking at Drupal and Wordpress codes to see how they do it, but I just can`t make heads or tails of these pre-made cms programs to be able to even figure out their code.

 

How can I make my code do it for automatically? Like when a user creates an account, a permalink is made right then and there or when they submit a picture posting it will be automatically created and functioning. (Ie, instead of http://mywebsite.com/picture.php?id=548578457 it will be http://mywebsite.com/username/title_of_picture/)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.