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!

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.
}

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!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.