简体   繁体   English

如何使用 Nginx 重定向编码的 url slug

[英]How to redirect an encoded url slug with Nginx

I have a strange url, (/%E2%80%8E) from an older version of a site that needs to be redirected to (/).我有一个奇怪的 url,(/%E2%80%8E) 来自旧版本的网站,需要重定向到 (/)。 I tried the following but it did not work:我尝试了以下但没有奏效:

location /%E2%80%8E {
  return 301 /;
}

Any help would be appreciated!任何帮助,将不胜感激!

You cannot use percent encoded URIs in the location statement.您不能在location语句中使用百分比编码的 URI。

I managed to match the URI by using three hexadecimal bytes.我设法通过使用三个十六进制字节来匹配 URI。 The regular expression syntax incudes a method for inserting arbitrary byte values by using the \\x escape sequence.正则表达式语法包含一种使用\\x转义序列插入任意字节值的方法。

For example:例如:

location ~ ^/\xE2\x80\x8E { return 301 /; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM