Nicolas Bouliane

Nginx redirects with unicode characters Posted on

On All About Berlin, some URLs have accented characters. Recently, I renamed /glossary/Bundesagentur für Arbeit to /glossary/Agentur für Arbeit. To make this redirect work in nginx, I had to add (*UTF8) in front of the regex pattern:2

# Before
rewrite "^/glossary/Bundesagentur für Arbeit" "/glossary/Agentur für Arbeit" permanent;

# After
rewrite "(*UTF8)^/glossary/Bundesagentur für Arbeit" "/glossary/Agentur für Arbeit" permanent;

This also works with nginx maps, and with redirects that use the return 301 /path/to/new-url; format.1

Sources and footnotes
  1. blog.rabin.io 

  2. Stack Overflow, Server Fault