Jump to content

Recommended Posts

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

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>

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?

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" />

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.