Jump to content

Mod-Rewrite Rule for Custom URLS (/userprofile.php?userid=1001 to /example)


CloudSex13

Recommended Posts

Hi,

 

I've been searching the web for a way to make the mod-rewrite rule work with custom URL's that the user picks.

 

I found one to shorten the page to just the user ID...

 

RewriteEngine On
RewriteRule ^([^/]*)$ /userprofile.php?userid=$1 [L]

 

...but I was hoping to get it to work with a custom URL a user has picked.

 

For example, a user's profile link is userprofile.php?userid=1001. They've picked "example" to be their custom URL, so the URL now would be www.example.com/example, which be a mask for userprofile.php?userid=1001.

 

This custom URL they picked would be stored in the database under their account.

 

Would anyone have any ideas? Thank you!

Link to comment
Share on other sites

Your question isn't any longer mod_rewrite related. All you need do is (within profile.php) look up the users profile data by this custom URL the user has picked. eg;

 

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT userdetails FROM users WHERE custom_id = '$id'";

  // now execute your query and make the page from the data provided.
}

Link to comment
Share on other sites

Thorpe,

 

I tested the idea just now and realized it's not what I'm looking for. I'm looking for user's to be able to access their profile from a link like this one:

 

http://www.example.com/userscustomurl

 

Right now, they can access their profile from a link like this one:

 

http://www.example.com/profile.php?id=1001

 

If you or anyone else has any further ideas how I could make this happen, please let me know. I appreciate your help!

 

 

Link to comment
Share on other sites

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.