BrendanMullan Posted May 13, 2011 Share Posted May 13, 2011 Hi my social networking site has users profiles like domain.com/members.php?username=user and i want domian.com/user or if easier domain.com/user/user but i have read many threads in here and tried out alot of the mod rewerites and none of them work, can someone help me please? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 13, 2011 Share Posted May 13, 2011 You can map domian.com/user/user to domain.com/members.php?username=user using RewriteEngine On RewriteRule user/([a-z0-9_-]+)/? members.php?user=$1 [NC,L] In members.php you will need to modify your existing links so they adopt your new url format. Mod_rewrite will not do this for you. For example you may output your links like this <a href="members.php?user=<?php echo $username; ?>"><?php echo $username; ?></a> You'll need to change the above to <a href="/user/<?php echo $username; ?>"><?php echo $username; ?></a> Quote Link to comment Share on other sites More sharing options...
BrendanMullan Posted May 13, 2011 Author Share Posted May 13, 2011 that got it but now when i go to the members page i cant retrive the users info from the $_GET['username']; anyone i can still do that? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 13, 2011 Share Posted May 13, 2011 Change the rewrite rule to RewriteRule user/([a-z0-9_-]+)/? members.php?username=$1 [NC,L] Quote Link to comment Share on other sites More sharing options...
BrendanMullan Posted May 13, 2011 Author Share Posted May 13, 2011 Ah i missed that lol. Anyway for this to only work with uses not images ect? My icon on my heaer is called icon.png and when i go to a members profile the image no longer shows (just shows broken image) and when i view the image it takes me to /user/icon.png acting as if thats a profile Edit.. Using ../ in front of the links on the page such as <a href="login.php">Login to ../login.php seems to work,. is that ok to use? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 13, 2011 Share Posted May 13, 2011 Because your url is now site.com/users/username for viewing a users profile. Your browser is thinking user/ is a directory. It is trying to load your links/images within this non existent directory. To prevent this start your url paths with a / For example <a href="/link.php">Link</a> OR <img src="/image.png" /> 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.