How do I redirect a URL with special (%C2%A0) characters in Nginx
I found out that I have link to one of URLs with some garbage behind that would generate some traffic, however whoever it placed it did it wrong:
/domain/sub-directory/%C2%A0
Therefore, I would like to redirect this URL to the one it was intended. However, I could not figure out how to do this properly.
I tried already:
location ^~ /sub-directory/(.*) { return 301 https://example.com/sub-directory/; }
and also
rewrite ^https://example.com/sub-directory/%C2%A0$ https://example.com/sub-directory/ permanent;
but none of them works. Any idea, how to fix this?
Solution 1:
You can represent it as a hex value in a regular expression.
For example:
rewrite ^(/sub-directory/)\xC2\xA0$ $1 permanent;