开发者

Dynamic and Clean URL

开发者 https://www.devze.com 2023-03-09 01:38 出处:网络
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:

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 scri开发者_运维知识库pt they wrote themselves I would be very happy to know about it. Thanks!


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 :)


Here is a very good tutorial regarding clean urls:

Clean URls

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消