2004-12-23

Apache's mod_rewrite and URI encoding...

For the rule "RewriteRule ^blog(.*)$ escrib/Escrib.php?arg=$1":

  • http://localhost/escrib/Escrib.php?arg=%252525 → arg is %2525 (correct)
  • http://localhost/blog/%252525 → arg is %25 (incorrect)

Argh. And according to the mailing list, there is no way around this.

So, what happens when a user wants to use a percentage sign in their titles?

  1. Title: "44% of US Citizens favour more restrictions on Muslims."
  2. Permalink: "/blog/44%25-of-us-citizens-favour-more-restrictions-on-muslims"
  3. Using mod_rewrite makes the variable in PHP: "/44%-of-us-citizens-favour-more-restrictions-on-muslims"

Phew. But:

  1. Title: "Apache hates %25!"
  2. Permalink: "/blog/apache-hates-%2525"
  3. Using mod_rewrite makes the variable in PHP: "/apache-hates-%"

Suggestions on what I should do? I think this would break even further if I start trying out some UTF-8 tests. (Yes, still a long way until IRIs will be supported!) I'd hate to only allow ASCII in permalinks... although if I can't guarantee that it won't break I may have to do so. Either that or only allow titles that are the same when encoded and double-decoded.

Update: D'oh! I'm a stupid-head. $_SERVER['REQUEST_URI']. Still, I'm leaving this here so others can learn from it :)

0 Comments:

Post a Comment

<< Home