Reply to Re: [PHP] mod_rewrite and getting url variables

Your name:

Reply:


Posted by Matthew Weier O'Phinney on 04/12/05 19:41

* 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация