This is a very easy tuturial about creating search engine friendly url's with
the help of mod_rewrite and some PHP functions.
Rewrite Function
This function parses an input into the
$_GET, $_REQUEST, and $HTTP_GET_VARS Globals.
If your script relies on register_globals
being enabled call extract( $_GET, EXTR_OVERWRITE );
after using this function to register again <br>the $_GET array pair values in to the global namespace
The input:
$request = the string variable you >need parsed into the global namespace
$array_delim = the array pair value deliminator
$pair_delim = the deliminator that seperates pair names from pairs values returns:
void or no return value;
Example Usage:
-------------------------------------------------------------------------------
In the .htaccess you have:
RewriteEngine On
RewriteBase /
RewriteRule ^somepage/(.*)\.html somepage.php?rewrite=$1 [L]
Your links:
Your original link url was:http://yoursite.com/somepage.php?id=20&name=funny
You change your url to: http://yoursite.com/somepage/id-20/name-funny.html
In the script somepage.php you put this at the top:
if( $_GET['rewrite'])
{
$request = $_GET['rewrite'];
mod_rewrite( $request, '/', '-' );
# if you have register_globals enables uncomment the following
# extract( $_GET, EXTR_OVERWRITE );
}
What happenes when a user clicks the link:
User sends request for "somepage/id-20/name-funny.html"
ModRewrite Engine is on and request matches pattern matches "somepage/"
ModRewrite engine changes the request to somepage.php?rewrite=id-20/name-funny
The PHP engine is called and the script is run
the $_GET['rewrite'] is processed by the mod_rewrite function
the mod_rewrite function changes this value "id-20/name-funny" into
$_GET['id'] = '20';
$_GET['name'] = 'funny';
...then if you depend on register_globals being on ( read converting an old script )
you call this:
extract( $_GET, EXTR_OVERWRITE );
right after the mod_rewrite function to put all the new $_GET variables into the global name space
There you have it!
a dynamic mod_rewrite tutorial made easy!
*/
function mod_rewrite( $request, $array_delim, $pair_delim )
{
global $_GET, $HTTP_GET_VARS, $_REQUEST;
$value_pairs = explode( $array_delim, $request );
$make_global = array();
foreach( $value_pairs as $pair )
{
$pair = explode( $pair_delim, $pair );
$_GET[$pair[0]] = $pair[1];
$_REQUEST[$pair[0]] = $pair[1];
$HTTP_GET_VARS[$pair[0]] = $pair[1];
}
}