You get a bonus - 1 coin for daily activity. Now you have 1 coin

Rewrite Engine does not accept URL-encoded strings

Practice



It's not just me — many colleagues, even English-speaking ones (although for them it's quite rare), have run into the mod_rewrite (rewrite engine) problem where it flatly refuses to accept strings containing "%", even though it supposedly should. So, as long as our URL string contains only standard, of course English, characters - everything's great. But as soon as mod_rewrite encounters an encoded string in its path - anything starting with the "%" sign simply doesn't exist for it.

Unfortunately, the creators of Apache (since this module was, after all, contributed to them) don't bother fixing this obvious bug, so for now you have to work around it (and this isn't always even possible) by making the URL look worse.


So, to get mod_rewrite to actually accept an escaped string containing % characters, you'll have to escape that string TWICE!

Normal PHP example:

$url = urlencode('это моя строка');

Example of what's needed for mod_rewrite:

$url = urlencode(urlencode('это моя строка'));


The same applies to other languages. And this all works fine as long as you're not simply trying to submit data through a form (via submit) - the browser, without any extra steps, for example via Javascript, won't double-escape the string on its own.

Applies to: Apache 2.2.16 and below (possibly above as well)
created: 2017-05-09
updated: 2026-03-09
383



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)