-1

I've seen this kind of 'format' on a lot of other community based websites and have always wondered how it is done. Basically my question is 'How does /users/9920018/elijah-pilcher work'.

What i mean by that is there a different directory for every user? i.e. /users/uid/ and how is it done.

At the moment I have a user database without anyway for the user to view their data, I know there's many ways to approach this but I would like to follow a common way (like stackoverflow).

I'm not looking for any code, just an explanation, if you need me to explain my question further just ask :). If this is a duplicate I apologize.

Dharman
  • 21,838
  • 18
  • 57
  • 107
  • Research `rewrite rules` or `pretty urls`. Maybe also a dup https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained. – user3783243 Jun 10 '18 at 06:31
  • Also, RESTful API may be an interesting topic for you. – Zev Jun 10 '18 at 06:31
  • Picked you a few duplicates (there are better ones, if you want to research further). One notable thing about the StackOverflow user urls though: the username is only decorative. Depends on the application logic if you want to match user names, or expose database-internal ids. (Often less professional IMO, but necessary on SO because user names don't have to be unique). – mario Jun 10 '18 at 06:36

1 Answers1

1

These are called path parameters. In a nutshell, there doesn't have to be a 1:1 mapping between the URL and a directory on your server.

You could direct anything under yoursite.com/users/ to a single servlet (or PHP script), and use the integer after /users/ as the ID of the user you want to retrieve the information for.

Mureinik
  • 252,575
  • 45
  • 248
  • 283