Nginx rewrite en dash in url

nginxregexrewrite

I have URL:s which contain one en dash character like this:

https://domain.dom/path/document-–-name-contains-a-single-en-dash

I tried to create a rewrite to replace the '-–-' string (dash,en dash, dash) with a single dash like so:

rewrite ^(.*)-–-(.*)$  $1-$2;

…to achieve urls like so:

https://domain.dom/path/document-name-contains-a-single-en-dash

But this doesn't seem to work. What am I doing wrong?

Best Answer

The en-dash (assuming UTF8) is actually represented as three bytes in the URL. You can place arbitrary bytes into the regular expression by using the \x escape.

For example:

rewrite ^(.*)-\xE2\x80\x93-(.*)$ $1-$2;
Related Topic