: Use .htaccess to convert user ID's to usernames? 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
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:
facebook.com/profile.php?id=4
It would take you to Mark Zuckerberg's profile page. However, you can also simply go to:
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?
More posts by @Barnes591
1 Comments
Sorted by latest first Latest Oldest Best
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= [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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.