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? Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/ 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> Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/#findComment-1215080 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? Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/#findComment-1215103 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] Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/#findComment-1215104 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? Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/#findComment-1215109 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" /> Link to comment https://forums.phpfreaks.com/topic/236332-twitter-like-user-link/#findComment-1215168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.