Nginx redirect rule with arabic characters

Viewed 70

I need to create an Nginx rule that redirects /ae/ar/أسافر%20من%20أجل/ to /ae/en. I've tried with these two rules:

  • rewrite (?i)^/ae/ar/أسافر%20من%20أجل(.*)$ http://$host/ae/en? permanent;
  • rewrite (?i)^/ae/ar/%D8%A3%D8%B3%D8%A7%D9%81%D8%B1%20%D9%85%D9%86%20%D8%A3%D8%AC%D9%84(.*)$ https://$host/ae/en? permanent;

But no one worked. Looks like the rule is ignored, any clues to make this rule work properly?

Thanks in advance!

1 Answers

Rewrite does not see the percent encoded characters. You should be able to leave the arabic characters as they are (UTF-8 characters within the configuration file) and replace the %20 with a single space. The entire regular expression should be surrounded with "s.

Alternatively, use a location statement:

location = "/ae/ar/أسافر من أجل/" { return 301 /ae/en; }
Related