1

I am trying to implement a SEO friendly URL.

I have a user detail page which has the url schema as such "$_SERVER["HTTP_HOST"]/[user-name]/[user-id]. I use the [user-id] to query user information in my database. However, if the [user-name] in the url does not match the user name that I query based on the database, I would like to auto correct the url in the browser.

For example there are two people, "mickey" and "minnie". mickey's user id is 1 and minnie is 2. So if a user key in "$_SERVER["HTTP_HOST"]/mickey/2", the system will check the database to make sure "mickey" in the url matches with the name of user id 2. If found out that it does not match, the system will redirect user to url "$_SERVER["HTTP_HOST"]/minnie/2".

How could I do that?

Thanks in advance=)

samayo
  • 16,163
  • 12
  • 91
  • 106
Jia-Luo
  • 3,023
  • 5
  • 16
  • 17

3 Answers3

0
  1. Fetch the user account based on it's id.
  2. Verify if the username is correct.
  3. If not: redirect the user.
Evert
  • 93,428
  • 18
  • 118
  • 189
0
  1. Look at the URL.
  2. Get the id from it.
  3. Calculate the expected URL based on that id.
  4. Check to see if it matches the requested URL
  5. Issue a 301 redirect if it does not.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0
header("Location: {$_SERVER["HTTP_HOST"]}/minnie/2");
Bradley
  • 2,071
  • 2
  • 21
  • 32