Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite and the ampersand

         

Nube2021

8:12 am on Dec 11, 2004 (gmt 0)

10+ Year Member



Hello, I have the following problem by rewriting an URL with mod_rewrite.

original URL:
productsite-games-&-software

RewriteRule:
RewriteRule productsite-(.*)$ destination.php?producttype=$1

In destination.php, the $_GET['producttype'] parameter doesn't contain "games-&-software" like expected. Instead of I receive $_GET[producttype]="games-" and $_GET[-software] which is empty. Also the use of urlencode(URL), htmlentities(URL) or the [NE]-Flag didn't solve this problem.

jdMorgan

3:38 pm on Dec 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nube2021,

Welcome to WebmasterWorld!

Try making the rule into an external redirect temporarily, so that you can see what URL is actually being passed into your script:


RewriteRule ^productsite-(.*)$ /destination.php?producttype=$1 [R=301,L]

I suspect you'll find that the ampersand has been encoded. That may be messing up the parameter parser in your script.

The next thing to try is to replace the ampersand with another URL-legal character, or perhaps with the word 'and'. Then see how your parameters parse out into the two variables.

Neither of these suggestions is intended as a fix. Rather, they are intended to locate more precisely where the problem is occurring.

We had a thread [webmasterworld.com] here yesterday reporting similar problems with non-latin characters in the URL. I haven't seen this before, and I'm wondering if this problem is new for Apache 2. Are you on Apache 2 or 1.3?

Jim

Nube2021

5:26 pm on Dec 11, 2004 (gmt 0)

10+ Year Member



Hi,

I use Apache2. Fortunately I have found a solution on a very good german board:
[php-resource.de...]

You just have to type this line in your .htaccess:
php_value arg_separator.input ";", or change it directly in your php.ini or in a script.

Apache causes this problem because it automaticly encodes a decoded URL, so that PHP parses two variables, what PHP shall do while the php.ini value "arg_separator.input" is set to "&". That value tells PHP that the & should be the seperator charatcter between the arguments in the Link. With the line above you can change the separator to any character you want. In this case I choosed the ";". A character that probably will never appear in my links.

Nube2021