1

I want to use .htaccess to convert the urls that link to profile pages from an ID number to a name. For example, on Facebook, if you were to go to:

https://facebook.com/profile.php?id=4

It would take you to Mark Zuckerberg's profile page. However, you can also simply go to:

https://facebook.com/zuck

...which is more user friendly and easier to remember. How can I use htaccess to convert an id number to a username? Do I need to send it to a php script to process and send back the name?

1

As well as storing a unique ID you'd want to store a unique (let's call it) URL for each user too. Or generate one when your user accounts are created. Then you can do a regular re-write rule something like this:

RewriteRule ^/([^/\.]+)/?$ /display-account.htm?account=$1 [NC,L]

Then write your display-account.htm page to grab the account URL parm and pull data from your database with it.

I use pretty much this exact method for some web apps that I've built. It works pretty flawlessly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.