dilum Posted November 12, 2007 Share Posted November 12, 2007 i have built a web site. that is a normal members register web site. so i want to give to member URL like this www.mysite.com/username. Example if some one type www.mysite.com/username so i want to display his profile with that same URL. like http://www.myspace.com/some_username i think this one has to be solve in htaccess. i tried lot of time but still i could not find a solution. so i want a help what i have to put to htaccess file and how i can read that from a PHP page (index.php) Thank you. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 12, 2007 Share Posted November 12, 2007 In htaccess you would have something like this : RewriteRule ^[a-zA-Z]*$ get_user.php?username=$1 The only problem with this is that it will rewrite ALL your urls to be like that. Quote Link to comment Share on other sites More sharing options...
dilum Posted November 12, 2007 Author Share Posted November 12, 2007 First thanks for your reply I tried it just now. When i visit the page it's giving Internal Server Error. May i ask? i put only code line that you gave. i did that one. Am i correct? Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 12, 2007 Share Posted November 12, 2007 add this just above it: RewriteEngine On RewriteBase / Quote Link to comment Share on other sites More sharing options...
aschk Posted November 12, 2007 Share Posted November 12, 2007 It depends, what URL did you go to? Do you have a file called get_user.php ? Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 12, 2007 Share Posted November 12, 2007 It depends, what URL did you go to? Do you have a file called get_user.php ? I think if the file didn't exist he'd just get a 404 not found error Quote Link to comment Share on other sites More sharing options...
dilum Posted November 12, 2007 Author Share Posted November 12, 2007 Thanks for all the reply. But still i have some problem. I added these lines to htaccess file RewriteEngine On RewriteBase / RewriteRule ^[a-zA-Z]*$ http://mydomain.com/index.php?username=$1 When I type "http://mydomain.com/smith" Iit redirect to the index page. This is the URL http://mydomain.com/index.php?username= But I need that name also (smith) get details for that user. But in that URL passing only username= So can you help me how to get that name also to a variable? Already i have declare a variable called $username = $_REQUEST['username']; Thanks. Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 12, 2007 Share Posted November 12, 2007 the code you've got in the .htaccess should make the url like this: http://mydomain.com/index.php?username=smith then just use $username = $_GET['username']; Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 12, 2007 Share Posted November 12, 2007 You all are missing a pair of round brackets here: RewriteEngine On RewriteBase / RewriteRule ^([a-zA-Z]*)$ http://mydomain.com/index.php?username=$1 $1 refers to the first pair of round brackets, $2 to the second etc. .. forget what was here, my mistake .. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 12, 2007 Share Posted November 12, 2007 Haha, whoops, my fault. Although shouldn't it be : ^([a-zA-Z]*)$ Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 12, 2007 Share Posted November 12, 2007 We all make faults, eh? Corrected. Quote Link to comment 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.