Re: mod_rewrite and getting url variables

From: Date: Tue, 12 Apr 2005 16:41:47 +0000
Subject: Re: mod_rewrite and getting url variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-212937@lists.php.net to get a copy of this message
* Chris W. Parker <cparker@swatgear.com>: > Ospinto <mailto:ospinto@hotmail.com> > on Tuesday, April 12, 2005 10:32 AM said: > >> I used mod_rewrite to change http://www.mysite.com/page/1 >> to >> http://www.mysite.com/page.php?id=1 to enable a search >> friendly url. > > Ok I'm with you. > >> Everything works fine, except that when I try to get the URL variable >> ($id) by using $_GET, it doesn't return anything. With >> http://www.mysite.com/page.php?id=1 it gets $id just fine. > > Now you've lost me. Those two statements seem to be in opposition to one > another. You can't get $id with $_GET but > http://www.mysite.com/page.php?id=1 works just fine? The URL is > a "GET" > URL since it has a querystring. When using mod_rewrite, if the rewrite rule does not include a pass-through, then the query string is not passed on to the script in question. So, if you request the page directly with: http://www.mysite.com/page.php?id=1 it will process correctly, but if you have a rewrite rule that doesn't have the pass-through flag, then when the URL is _rewritten_ to the above, the page is requested _without_ the query string -- even though the rule rewrites the URL with a query string. A rule that would (probably) work would look something like this: RewriteRule page/(.*) /page.php?id=$1 [L,PT] -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.general (#212937) next »