Score:1

How do I redirect a URL with special (%C2%A0) characters in Nginx

hk flag

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?

Paul avatar
cn flag
Try: `location ^~ /sub-directory/ { return 301 https://example.com/sub-directory/$request_uri; }`.
Score:1
jp flag

You can represent it as a hex value in a regular expression.

For example:

rewrite ^(/sub-directory/)\xC2\xA0$ $1 permanent;
user3553828 avatar
hk flag
Thanks a lot this fixed it!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.