[svlug] Help with rewrite rules?

Drew Bertola drew at drewb.com
Sat Jul 5 18:17:01 PDT 2008


Skip Evans wrote:
> Hey all,
> 
> I need help getting a rewrite rule working that 
> will translate a URL into another with args that 
> can be read in PHP with $_GET.
> 
> I think in addition to the rule itself, I have a 
> config issue that is stopping me from testing it.
> 
> Basically, I need a rule that would translate
> 
> http://www.varsitybeat.com/wi/madison
> 
> into
> 
> http://www.varsitybeat.com?st=wi&sc=madison
> 
> Likewise it should do the same if the www is not 
> included.

Hey Skip,  think about using another approach.  Have the rewrite rules 
redirect anything that matches the pattern in question to a script that 
then parses $_SERVER['REQUEST_URI'] or $_SERVER['SCRIPT_NAME'].

So, you could have, say, router.php

<?php

// cook the input as required.
list($state, $city) = explode('/', $_SERVER['SCRIPT_NAME']);

... validate, etc ...

Sound good?

-- 
Drew Bertola

-------------------------------------------------
*   PHP/LAMP Consultant, ZCE-1000               *
*                                               *
*   Tel: 408-966-6671                           *
*                                               *
*   current resume:                             *
*   http://drewb.com/blog/about/resume/         *
-------------------------------------------------




More information about the svlug mailing list