I am going to start a new practice here. Every now and again I’m going to post some PHP code with some explanation. Today, I’m going to write about what I’ve been calling “pretty URLs” and how to create and manage them in PHP.
PHP includes a variable in the superglobal scope $_SERVER called “PATH_INFO.” PATH_INFO includes information entered after the name of the requested script.
Let’s use firsttube.com as an example. The URL of a story is constructed as such:
The story is also accessible as /read.php?id=[id]
So how do we construct this so-called “pretty URL?” Using PATH_INFO. Read on for details.