PHPBuilder - Revisited: Build Dynamic Pages With Search Engines in Mind Page 4



RSS Twitter
Articles Tricks And Hacks

Revisited: Build Dynamic Pages With Search Engines in Mind - Page 4

by: Tim Perdue
|
July 30, 2000

The following code is what I used in the construction of Gotocity.com. My goal was, as I mentioned, to eliminate all '?' and '&' characters from the URL. I wanted to drill down from the general (country, in this case the US) to the specific (a given topic page in a given city in the country specified).
Fortunately, all cities in the US are given a unique identifier, a ZIP code, and each city also resides in a state. So you can drill from Country -> state -> city -> topic page in a logical fashion.
The important thing to note is that, if you're viewing a "country" page, then the 'state' won't be present in the URL. If you're viewing a 'state' page, both 'country' and 'state' are in the url, so you can use both as criteria when you select from the database.
The URL string is set up in a global variable called $REQUEST_URI. All you have to do is examine the string and figure out where you're at. I do that by explode()'ing the string using the / separator.

<?php

/*
Sample URLs:
/local/2/us/IA/a/50613/apartment/ - apartments in Cedar Falls, IA
/local/2/us/IA/a/         - group of cities in Iowa
/local/2/us/              - States in the US
/local/1/us/IA/a/50301/       - Des Moines City.net
*/

$url_array=explode("/",$REQUEST_URI);  //BREAK UP THE URL PATH
                       //    USING '/' as delimiter
$url_affil_num=$url_array[2];      //Co-Branding info
$url_country=$url_array[3];        //Which Country?
$url_state=$url_array[4];          //Which State?
$url_alpha_state=$url_array[5];    //Cities starting with a-g
$url_zip=$url_array[6];        //If present, build thispage
$url_content=$url_array[7];        //If present, build a sub-
                       //    page for this city

/*
separate includes were designed to fetch the affiliate cobranding
and build appropriate style sheets on the fly. Data validation is
done prior to each query. If a URL is incorrect, bow out gracefully
or redirect home
*/

if($url_zip) {

    
/*
    If present, query the Zip code database and build the page.
    Inside the city.inc, we will check for which "content page" 
    we are building, if any.
    */

} elseif ($url_state) {

    
/*
    If URL PATH ends here, query Zip code database,
    selecting DISTINCT cities in this state
    */

} elseif ($url_country) {

    
/*
    If URL PATH ends here, query ZIP code database,
    selecting DISTINCT states for this country
    */

} else {

    
/*
    must be mal-formed. Redirect to home
    */

    
Header"Location:  http://db.gotocity.com/local/2/us/");
    exit;
}

?>
There, now you have all the building blocks you need to create useful, dynamic, AND search-engine friendly web pages by the millions.
--Tim

« Previous Page
1
|
2
|
3
|
4

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tim Perdue

Comment:



Comment:

(Maximum characters: 1200). You have characters left.