0

I have a file called www.example.com/profile.php that collects data for each profile in the database. So ex. 1 profile would have the url www.example.com/profile.php?ID=1.

I want to change so the URL goes from www.example.com/profile.php?ID=1 to www.example.com/john-doe which is profile 1s first and lastname.

The first and last name are in separate database fields.

Anyone that could help me make this possible? I guess it would be changed in the .htaccess file but I have never worked with .htaccess before so I'm total noob at that.

Howli
  • 12,291
  • 19
  • 47
  • 72
Freddos
  • 35
  • 6
  • This `htaccess` alone it is not possible unless you passed the first and last name with the id. – Howli Apr 08 '14 at 19:12
  • Okay..is it possible to do it so the URL changes to just the username? So from "example.com/profile.php?ID=1 to "example.com/*username*"? – Freddos Apr 08 '14 at 19:15
  • From the example you gave, afaik the only thing you can do with it is to show `www.example.com/1` or `www.example.com/profile/1`. You could get the htaccess file to redirect it to a php page, which will grab the id, look it up in the database get the users first and last name. Combine them together and change the url, but you would need to make sure it is unique. – Howli Apr 08 '14 at 19:33

1 Answers1

0

You can do it at ease. Here's a link to another question where this was answered.

Unless you are going to make sure no two have the same first and last name, I do not recommend the way you want. You should either use a unique username or append id to rewritten url. www.example.com/john.doe or www.example.com/1/john-doe

Community
  • 1
  • 1
Santosh Achari
  • 2,936
  • 7
  • 30
  • 52
  • Yes it´s fine to change the URL to www.example.com/johndoe. Does that work through the guide you linked? – Freddos Apr 08 '14 at 19:28
  • Yes. http://stackoverflow.com/questions/16388959/url-rewriting-with-php You can also read here. http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/ – Santosh Achari Apr 08 '14 at 19:29