Announcement

Collapse
No announcement yet.

preg_match_all problem for mod_rewrite

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • preg_match_all problem for mod_rewrite

    PHP Code:
    <?php
    // mod_rewrite, Jeroen's way
    // file: cleanurl.inc.php
    // date: May 11, 2005
     
    $uri $_SERVER['REQUEST_URI'];
    //preg_match_all('/^\/([\/a-z\\0-9\\-_\\.\/]*)(.*)\\.html/', $uri, $uri_array, PREG_PATTERN_ORDER);
    preg_match_all('/^\/([\/a-z\\-_\\.\/]*)(.*)\\.html/'$uri$uri_arrayPREG_PATTERN_ORDER);
     
    $page=$uri_array[1][0];
    $optional=$uri_array[2][0];
     
    // url => forumid mapping
    $url_forum=array(
    "nfl" => 280,
    "nhl" => 282,
    "nba" => 283,
    "mlb" => 281,
    "ncaa" => 284,
    "mark_chalifoux" => 356,
    "a_smith" => 357,
    "sara_normand" => 358,
    "chris_shryock" => 359,
    "marcus_hartman" => 360,
    "w_peery" => 361,
    "john_katrus" => 362,
    "callie_spear" => 363,
    "john_siskos" => 364,
    "ishkur" => 365,
    "mike_simonds" => 366,
    "interviews" => 350,
    "jackass" => 181,
    "nfl/cleveland-browns" => 225,
    "nfl/dallas-cowboys" => 226,
    "nfl/denver-broncos" => 227,
    "nfl/detroit-lions" => 228,
    "nfl/green-bay-packers" => 229,
    "nfl/houston-texans" => 230,
    "nfl/indianapolis-colts" => 231,
    "nfl/jacksonville-jaguars" => 232,
    "nfl/kansas-city-chiefs" => 233,
    "nfl/miami-dolphins" => 234,
    "nfl/minnesota-vikings" => 235,
    "nfl/new-england-patriots" => 236,
    "nfl/new-orleans-saints" => 237,
    "nfl/new-york-giants" => 238,
    "nfl/new-york-jets" => 239,
    "nfl/oakland-raiders" => 240,
    "nfl/philadelphia-eagles" => 241,
    "nfl/pittsburgh-steelers" => 242,
    "nfl/san-diego-chargers" => 243,
    "nfl/san-francisco-49ers" => 244,
    "nfl/seattle-seahawks" => 245,
    "nfl/st-louis-rams" => 246,
    "nfl/tampa-bay-buccaneers" => 247,
    "nfl/tennessee-titans" => 248,
    "nfl/washington-redskins" => 249,
    "nba/atlanta-hawks" => 319,
    "nba/boston-celtics" => 320,
    "nba/charlotte-bobcats" => 321,
    "nba/chicago-bulls" => 322,
    "nba/cleveland-cavaliers" => 323,
    "nba/dallas-mavericks" => 324,
    "nba/denver-nuggets" => 325,
    "nba/detroit-pistons" => 326,
    "nba/golden-state-warriors" => 327,
    "nba/houston-rockets" => 328,
    "nba/indiana-pacers" => 329,
    "nba/los-angeles-clippers" => 330,
    "nba/los-angeles-lakers" => 331,
    "nba/memphis-grizzlies" => 332,
    "nba/miami-heat" => 333,
    "nba/milwaukee-bucks" => 334,
    "nba/minnesota-timberwolves" => 335,
    "nba/new-jersey-nets" => 336,
    "nba/new-orleans-hornets" => 337,
    "nba/new-york-knicks" => 338,
    "nba/orlando-magic" => 339,
    "nba/philadelphia-76ers" => 340,
    "nba/phoenix-suns" => 341,
    "nba/portland-trail-blazers" => 342,
    "nba/sacramento-kings" => 343,
    "nba/san-antonio-spurs" => 344,
    "nba/seattle-supersonics" => 345,
    "nba/toronto-raptors" => 346,
    "nba/utah-jazz" => 347,
    "nba/washington-wizards" => 348,
    "nhl/anaheim-mighty-ducks" => 250,
    "nhl/atlanta-thrashers" => 251,
    "nhl/boston-bruins" => 252,
    "nhl/buffalo-sabres" => 253,
    "nhl/calgary-flames" => 254,
    "nhl/carolina-hurricanes" => 255,
    "nhl/chicago-blackhawks" => 256,
    "nhl/colorado-avalanche" => 257,
    "nhl/columbus-blue-jackets" => 258,
    "nhl/dallas-stars" => 259,
    "nhl/detroit-red-wings" => 285,
    "nhl/edmonton-oilers" => 260,
    "nhl/florida-panthers" => 261,
    "nhl/los-angeles-kings" => 262,
    "nhl/minnesota-wild" => 264,
    "nhl/montreal-canadiens" => 263,
    "nhl/nashville-predators" => 265,
    "nhl/new-jersey-devils" => 266,
    "nhl/new-york-islanders" => 267,
    "nhl/new-york-rangers" => 268,
    "nhl/ottawa-senators" => 269,
    "nhl/philadelphia-flyers" => 270,
    "nhl/phoenix-coyotes" => 271,
    "nhl/pittsburgh-penguins" => 272,
    "nhl/san-jose-sharks" => 273,
    "nhl/st.-louis-blues" => 274,
    "nhl/toronto-maple-leafs" => 275,
    "nhl/tampa-bay-lightning" => 276,
    "nhl/vancouver-canucks" => 277,
    "nhl/washington-capitals" => 278,
    "mlb/anaheim-angels" => 289,
    "mlb/arizona-diamondbacks" => 290,
    "mlb/atlanta-braves" => 291,
    "mlb/baltimore-orioles" => 292,
    "mlb/boston-red-sox" => 293,
    "mlb/chicago-cubs" => 294,
    "mlb/chicago-white-sox" => 295,
    "mlb/cincinnati-reds" => 296,
    "mlb/cleveland-indians" => 297,
    "mlb/colorado-rockies" => 298,
    "mlb/detroit-tigers" => 299,
    "mlb/florida-marlins" => 300,
    "mlb/houston-astros" => 301,
    "mlb/kansas-city-royals" => 302,
    "mlb/los-angeles-dodgers" => 303,
    "mlb/minnesota-twins" => 304,
    "mlb/milwaukee-brewers" => 305,
    "mlb/montreal-expos" => 306,
    "mlb/new-york-mets" => 307,
    "mlb/new-york-yankees" => 308,
    "mlb/oakland-athletics" => 309,
    "mlb/pittsburgh-pirates" => 310,
    "mlb/philadelphia-phillies" => 311,
    "mlb/san-diego-padres" => 312,
    "mlb/san-francisco-giants" => 313,
    "mlb/seattle-mariners" => 314,
    "mlb/st.-louis-cardinals" => 315,
    "mlb/tampa-bay-devil-rays" => 316,
    "mlb/texas-rangers" => 317,
    "mlb/toronto-blue-jays" => 318,
    "mlb/washington-nationals" => 306,
    "ncaa/basketball" => 42,
    "ncaa/baseball" => 44,
    "ncaa/football" => 41
    );
     
    if (!empty(
    $url_forum[$page]))
    {
    $_REQUEST['f']=$url_forum[$page];
    if (!empty(
    $optional))
    {
    $_REQUEST['pagenumber']=$optional;
    // set 'page' as well, just to be sure... the old .htaccess rewrote to page, not pagenumber
    $_REQUEST['page']=$optional;
    }
    }
    else 
    // handle special cases
    {
    switch (
    $page)
    {
    case 
    "index":
         if (!empty(
    $optional))
         {
        
    $_REQUEST['pagenumber'] = $optional;
        
    $_REQUEST['page'] = $optional;
    }
    break;
    case 
    "article":
         
    $_REQUEST['do'] = 'feature';
         if (!empty(
    $optional))
         {
        
    $_REQUEST['t'] = $optional;
    }
    break;
    case 
    "news":
         
    $_REQUEST['do'] = 'default';
         break;
    case 
    "news-":
    $news explode('-',$optional);
    $_REQUEST['f'] = $news[0];
    $_REQUEST['page'] = $news[1];
    $_REQUEST['pagenumber'] = $news[1];
    unset(
    $news);
    break;
     
    case 
    "makenews":
         
    $_REQUEST['do'] = 'make';
         if (!empty(
    $optional))
                {
        
    $_REQUEST['f'] = $optional;
    }
    break;
     
    case 
    "archive":
         
    $_REQUEST['do'] = 'archive';
         
    $arch explode('-',$optional);
         
    $_REQUEST['f'] = $arch[0];
         if (isset(
    $arch[1]))
                {
        
    $_REQUEST['month'] = $arch[1];
    }
         if (isset(
    $arch[2]))
                {
        
    $_REQUEST['year'] = $arch[2];
    }
    unset(
    $arch);
         break;
     
    default:
    // redirect to [url]http://www.sportsrant.com[/url]
    //Header('HTTP/1.1 301 Moved Permanently');
    //Header('Location: http://www.sportsrant.com');
    //exit;
     
    }
    }
     
    // print_r($_REQUEST);
    // echo "<br />$page / $optional<br />$uri";
     
    // clean up motor's internal variables
    unset($url_forum);
    unset(
    $page);
    unset(
    $optional);
    unset(
    $uri);
     
    ?>


    this code is for a mod_rewrite function that I have on my site. the only problem is that in the preg_match_all the programmer forgot to add in the ability to have numbers in the url.

    Example:

    the url for a team page works accoriding to the array: (example)

    http://www.sportsrant.com/nfl/san-diego-chargers.html

    and the teams with numbers in them do not: (example)

    http://www.sportsrant.com/nfl/san-francisco-49ers.html

    it redirects back to the home page!

    Can someone please help me fix the preg_match_all

    TIA,

    Mike
    Founder

    http://www.sportsrant.com
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X