
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];
}
}
Added by roScripts on April-18-2007, 3:53 pm
