Mobile app version of vmapp.org
Login or Join
Barnes591

: 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

@Barnes591

Posted in: #Htaccess #Php #UrlRewriting

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sherry384

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme