Re: mod_rewrite and getting url variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Chris W. Parker <cparker@xxxxxxxxxxxx>:
> Ospinto <mailto:ospinto@xxxxxxxxxxx>
>     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@xxxxxxxxxx         | http://vermontbotanical.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux