Re: rewrite rule help anyone?

From: Date: Sun, 23 Feb 2003 22:36:40 +0000
Subject: Re: rewrite rule help anyone?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136767@lists.php.net to get a copy of this message
No takers??? Did I say, Please! Thanks! Shawn "Shawn McKenzie" <nospam@mckenzies.net> wrote in message news:20030222212546.92564.qmail@pb1.pair.com... > Slightly off topic, but I have some PHP also ;-) > > I am trying to make search engine friendly URLs for a site, but want this to > be fairly dynamic and work with any new script and vars. > > If anyone would be willing, I need help on a mod_rewrite rule or rules? I'm > thinking it should be fairly simple, but I know nothing about reg > expressions. Maybe not the greatest, but here's the code that generates the > HTML with altered URLs. This works great, but then I need Apache to rewrite > these. > > ---This: > index.php?file=test&cmd=display&what=all > ---Becomes: > index-get-file-is-test+cmd-is-display+what-is-all.html > > --Here's the code: > > ob_start(); > echo $htmlpage; > $newdisplay = ob_get_contents(); > ob_clean_flush(); > echo rewrite($newdisplay); > > function rewrite($newdisplay) > { > $search = array( > ".php?", ".php", "=", "&amp;", > "&"); > > $replace = array( > "-get-", "", "-is-", "+", "+"); > > $hrefs = find_hrefs($newdisplay); > $tmphrefs = str_replace($search, $replace, $hrefs); > foreach($tmphrefs as $key => $array) { > $newhrefs[$key] = $array.".html"; > } > $newdisplay = str_replace($hrefs, $newhrefs, $newdisplay); > > return $newdisplay; > } > > //finds href=" in the string containing the html > function find_hrefs($tmpcontent) > { > while($start = strpos($tmpcontent, 'href="', $end)) { > $start = $start +6; > $end = strpos($tmpcontent, '"', $start); > $href[] = substr($tmpcontent, $start, $end - $start); > } > return $href; > } > > TIA, > Shawn > >

« previous php.general (#136767) next »