-1

So I'm build a site that has user profiles. what I want to do is grab from the database the users username and display it in the url, so something like this:

example.com/profile/derrick in stead of showing (example.com/profile.php?id=123)

I always want to do this with the photos that they upload as well. I want to grab the title of the photo and make it the url:

example.com/shots/my-photo-title-here in stead of showing (example.com/shots.php?id=13)

If anyone has a good tutorial out there, or script they wrote themselves I would be very happy to know about it. Thanks!

Derrick
  • 9
  • 1
  • 4
  • Found these 2 tutorials, worth going through. http://forum.codecall.net/topic/74170-clean-urls-with-php/ and http://www.cutcodedown.com/tutorials/friendlyURL/ – Fernando Silva Mar 04 '14 at 22:31

3 Answers3

3

Use: $urlarray = explode("/", $_SERVER['REQUEST_URI']);

Example: Url: www.mysite.com/this/is/it

$urlarray[1] will by this
$urlarray[2] will by is
$urlarray[3] will by it

There from you can try it out :)

Leo
  • 51
  • 5
0

There is a nice generator for clean URLs: http://www.generateit.net/mod-rewrite/.

A. Z.
  • 728
  • 1
  • 11
  • 28
0

Here is a very good tutorial regarding clean urls:

Clean URls

One of the better ones I found that actually worked. Good Luck

lockdown
  • 1,456
  • 5
  • 16
  • 32