November 16, 2004

Flickr like url styling.

There has been some talk lately about Flickr's url structure. Specifically, presenting a url like so:

http://flickr.com/photos/tags/honda

Instead of

http://flickr.com/photos/tags?tagname=honda&etc=etc&sid=AB1231454C

or:

http://flickr.com/photos/case/1520544/

Instead of:

http://flickr.com/photos?asset=ABCF534123137797198298X9897B9878987C98F797

You get the point. So many developers don't do this, but the nice thing is that, intrepid developers, you can do this in practically any language very easily. If you haven't tried it, you can pull it right out of script name.

Apache does some magic with this. For instance. If you go to this url :

http://dibona.com/~chris/index.html

Then you'll see a little php script that prints out the script name.

But look what happens when you go here:

http://dibona.com/~chris/index.html/Chris

Here is the super simple code for that page:

<?php
$urisplit=array();
$urisplit = split("/",$_SERVER['REQUEST_URI']);
$name= $urisplit[count($urisplit)-1];
print "Hi There $name !<p>";
print "Request URI = {$_SERVER['REQUEST_URI']}";
?>

An exercise for you, my reader. Have it do multiple tagging, for instance, give a result like "Hi There Chris and Bob" or something.

Chris DiBona
Posting From: Mountain View, Ca
Posting Via: Blogger Interface

3 comments:

Kona said...

Now we have to know php code to enjoy your site. I'm just a dumb system admin who does not code, but is a nice trick to shorten url. But I use tinyurl.com.

Chris DiBona said...

you can skip this post then :-) They won't all be code filled.

Chris

James Byers said...

There's one thing to watch out for if you're running Apache. Apache 1.3 works fine out of the box for URLs like:

/index.php/hi/chris/

However, in Apache 2.0, you must set the configuration directive AcceptPathInfo to On. Otherwise, Apache will return a 404.

James