Encoding double quotes in Apache

apache-2.4mod-rewrite

Tomcat disallows any presence of '"' (double quote) characters in URL, it is treated as invalid character as per RFC 7230.

However I have lot of service clients who are still taking to my service with URLs like http://abcd.com/userservice?user="donald", I am looking for the ways to rewrite this URL to http://abcd.com/userservice?user=%20donald%20. I have to do this for multiple services (~20).

I looked at https://stackoverflow.com/questions/1279681/mod-rewrite-replace-underscores-with-dashes but it doesn't help my use-case. Apache doesn't seem to let users rewrite query parameters. Any suggestions?

Best Answer

This is a task for the client i.e. browser. If you type http://example.com/userservice?user="donald" to the address bar, it gets automatically encoded with the Percent-Encoding (RFC 3986, 2.1; mentioned in RFC 7230, 2.7.3), resulting the actual query to start with:

GET /userservice?user=%22donald%22 HTTP/1.1
Host: example.com

The %20 you mentioned in your question is the same for ASCII Space character, 0x20, whereas the %22 represents ASCII " (double quote, 0x22). Furthermore, literal % would became %25 etc.

You could rewrite %22 to %20, but I think this is rather just a mistake.

Just to be more complete, here's a chart. For Percent-Encoding, look at the column Hex.

ASCII Hex Symbol     ASCII Hex Symbol     ASCII Hex Symbol     ASCII Hex Symbol

32    20  (space)    39    27    '        46    2E    .        95    5F    _
33    21    !        40    28    (        47    2F    /        96    60    `
34    22    "        41    29    )        64    40    @        123   7B    {
35    23    #        42    2A    *        91    5B    [        124   7C    |
36    24    $        43    2B    +        92    5C    \        125   7D    }
37    25    %        44    2C    ,        93    5D    ]        126   7E    ~
38    26    &        45    2D    -        94    5E    ^        127   7F