13

I am encountering a problem with a get parameter in conjunction with a htaccess rewrite rule. Below is the urlencode()'ed link; the rewrite rule I use to redirect to index.php, and lastly, a print_r($_GET) on the index.php. As you can see, the urlescaped ampersand is not part of the value for variable static, but instead and contrary to my expectation gets interpreted as a variable seperator. Why?

Initial link:

<a href="static/Game-Tech-%26-Arts-Lab">link</a>

.htaccess:

RewriteRule ^static/(.*)$ /index.php?static=$1 [L]

index.php:

Array ( [static] => Game-Tech- [-Arts-Lab] => )
kontur
  • 4,934
  • 2
  • 36
  • 62
  • How did the `$_SERVER["QUERY_STRING"]` look for that request? And does the rewriting not occur when you invoke the `index.php?static=...` manually? – mario Dec 11 '11 at 20:39
  • Manually browsing to "index.php?static=Game-Tech-%26-Arts-Lab" shows the page just fine - the $_SERVER["QUERY_STRING"] reads "[QUERY_STRING] => static=Game-Tech-&-Arts-Lab" – kontur Dec 11 '11 at 20:51

1 Answers1

26

Ah, okay. Interesting. It seems there is a special solution for keeping that ampersand specifically escaped. Use the [B] flag for Rewriterules.

RewriteRule ^static/(.*)$ /index.php?static=$1 [L,B]

This is supposed to urlencode special characters when interpolating the $1 placeholder. It only works with Apache 2.2 however I believe.

Found a few references:

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291