BelovedDoll Posted September 12, 2010 Share Posted September 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213250-usernamewebhostcom/ Share on other sites More sharing options...
wildteen88 Posted September 13, 2010 Share Posted September 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213250-usernamewebhostcom/#findComment-1110496 Share on other sites More sharing options...
BelovedDoll Posted September 14, 2010 Author Share Posted September 14, 2010 What form of code is mod_rewrite? Is it a php thing? Quote Link to comment https://forums.phpfreaks.com/topic/213250-usernamewebhostcom/#findComment-1111028 Share on other sites More sharing options...
wildteen88 Posted September 14, 2010 Share Posted September 14, 2010 mod_rewrite isn't a coding language as such. It is a module which extends Apaches functionality. There is not much to learn of mod_rewrite. Have a read of the Apache documentation on mod_rewrite for how it works. However you will want to have a good understanding of regular expressions too. Quote Link to comment https://forums.phpfreaks.com/topic/213250-usernamewebhostcom/#findComment-1111034 Share on other sites More sharing options...
BelovedDoll Posted October 20, 2010 Author Share Posted October 20, 2010 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/) Quote Link to comment https://forums.phpfreaks.com/topic/213250-usernamewebhostcom/#findComment-1124476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.