percent-encoding

mod_rewrite rule to enforce canonical percent-encoding

We have a PHP app with a dynamic URL scheme which requires characters to be percent-encoded, even "unreserved characters" like parentheses or aphostrophes which aren't actually required to be encoded. URLs which the app deems to be encoded the "wrong" way are canonicalized and then redirected to the "right" encoding. But Google and othe...

PHP: comparing URIs which differ in percent-encoding

In PHP, I want to compare two relative URLs for equality. The catch: URLs may differ in percent-encoding, e.g. /dir/file+file vs. /dir/file%20file /dir/file(file) vs. /dir/file%28file%29 /dir/file%5bfile vs. /dir/file%5Bfile According to RFC 3986, servers should treat these URIs identically. But if I use == to compare, I'll end up...

Turn a hex string into a percent encoded string in Python

I have a string. It looks like s = 'e6b693e6a0abe699ab'. I want to put a percent sign in front of every pair of characters, so percentEncode(s) == '%e6%b6%93%e6%a0%ab%e6%99%ab'. What's a good way of writing percentEncode(s)? (Note, I don't care that unreserved characters aren't converted into ASCII.) I can think of big verbose ways o...