Forum Moderators: mack

Message Too Old, No Replies

using php urlencode with mod rewrite

only getting back the first word not the whole term

         

proper_bo

4:41 pm on Oct 14, 2005 (gmt 0)

10+ Year Member



Hello all,

I use mod rewrite to change a blah-widget.html to a .php?blah=widget

the problem has arisen recently where if the widget is more than one word I cannot get php to grab more than the first word after urlencode then mod rewrite then urldecode.

Example:
I want to transfer the term "widget & brown" over a link
php creates the link site.com/blah-widget+%26+brown.html
I use mod rewrite to change the url to search.php?blah=widget+%26+brown and then use urldecode to try and get the term back. The problem is that the variable only ever grabs the first word (widget in this case). The rewrite rule I use it:
RewriteRule ^widget-(.+).html search.php?blah=$1

So am I getting it all wrong with the mod rewrite or is there something I should be doing with the php?

Thank you.

jatar_k

4:43 pm on Oct 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you output $_GET['blah'] in your php script do you get the whole string?

proper_bo

4:57 pm on Oct 14, 2005 (gmt 0)

10+ Year Member



No I am just getting widget.

And I made a mistake above. Should be

RewriteRule ^blah-(.+).html search.php?blah=$1

Thanks

jatar_k

5:01 pm on Oct 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my wild guess

in this particular instance 'widget & brown' everything is acting as expected due to the & which denotes a new variable

proper_bo

5:15 pm on Oct 14, 2005 (gmt 0)

10+ Year Member



but php converts that to %26 and mod rewrite does not change it back. urldecode changes it back to & and by then it makes no difference does it not?

jatar_k

6:00 pm on Oct 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if echo $_GET['blah'] only gives you the first word then that's all there is

you could look at the output from

echo '<pre>';
print_r($_GET);
echo '</pre>';

then see what you have to work with

proper_bo

10:20 am on Oct 15, 2005 (gmt 0)

10+ Year Member



If it is all there is then the mod rewrite must only be grabbing the first word from the static address to turn it into dynamic.

blah-widget+%26+brown.html

must only be becoming

search.php?blah=widget
instead of
search.php?blah=widget+%26+brown

so what is wrong with the rewrite line:

RewriteRule ^blah-(.+).html search.php?blah=$1

?

proper_bo

3:55 pm on Oct 15, 2005 (gmt 0)

10+ Year Member



Ok I have found the problem but I am still looking for the solution.
The problem is with passing the & (&amp;) character through urlencode mod rewrite and urldecode.
The browser (firefox in my case) turns both %26 and &amp; back into the & character before php can get a hold of it and then spits an error.

Are there any tips on passing & (&amp;) through a url and is it a known issue?