Search Engine Friendly URLs
Category: PHPReviewed by: redemption
Reviewed on: Oct 11 2003
» Discuss this topic ( Posts)
A simple method for implementing Search Engine Friendly URLs
The easiest method for Search Engine Friendly URLs is to embed the variables within the request URL like so:
http://www.domain.com/files/members.php/us/ca/5/
All we've done in the above URL is add / between each variable and after the filename of the script. Apache and other popular web servers will correctly understand that you are trying to access the members.php script within the files directory and will kindly ignore anything after the .php. Why does that happen? Because Apache has a "look back" feature that will keep looking up the path until it finds an active file.
Note: For Apache 2.X users - In Apache 2 and up. The URL "look back" feature is off by default. In your .htaccess or httpd.conf file you must have a section pertaining to the directory which contains your php scripts. There you must add AcceptPathInfo On as such: [code]
Ok now in your script you include the following:
<P>/* <BR>break down the URL into it's token parts. The URLs look like: <BR>http://www.domain.com/files/members.php/us/ca/5/ <BR>*/ <BR>$tokens = split("/", $REQUEST_URI); <P>$country = $tokens[2]; //what country to search <BR>$state = $tokens[3]; //what state to search <BR>$page = $tokens[4]; //what page we're on <BR> <P>/* <BR>Here begins the code to grab the members... <BR>*/ <BR>
See the simple thing to remember is that we're using the REQUEST_URI
server variable. This variable is valid through PHP3 and PHP4 up to the current
4.3.3 version. For PHP4 users you may use $_SERVER["REQUEST_URI"] instead of
just $REQUEST_URI if you are following the recommended secure variable model.

