Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
nginx转义(+;)登录重写规则_Nginx_Nginx Config - Fatal编程技术网

nginx转义(+;)登录重写规则

nginx转义(+;)登录重写规则,nginx,nginx-config,Nginx,Nginx Config,我正在尝试根据Nginx配置中的映像名称重定向一些点击 这就是它现在的样子: location / { rewrite ^/static-v3/(.*)/creditcard_sslseals_public.png https://somenewurl.com/credit-card-seals.png permanent; rewrite ^/static-v3/(.*)/creditcard+sslseals_

我正在尝试根据Nginx配置中的映像名称重定向一些点击

这就是它现在的样子:

        location / {

                rewrite ^/static-v3/(.*)/creditcard_sslseals_public.png https://somenewurl.com/credit-card-seals.png permanent;
                rewrite ^/static-v3/(.*)/creditcard+sslseals_public.png https://somenewurl.com/credit-card-seals.png permanent;

                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
因此,文件名为
creditcard\u sslseals\u public.png
的第一个条件工作正常,但第二个条件不起作用,因为图像名称中有一个
+
符号,如
creditcard+sslseals\u public.png
,所以我得到了404


如何在第二个条件中转义+而将regex保留在
^/static-v3/(.*)
之前?

在正则表达式中,
+
具有特殊含义,需要转义

一个选项是使用反斜杠转义字符:

^/static-v3/(.*)/creditcard\+sslseals_public.png
^/static-v3/(.*)/creditcard[+]sslseals_public.png
或者,创建仅包含一个字符的字符类:

^/static-v3/(.*)/creditcard\+sslseals_public.png
^/static-v3/(.*)/creditcard[+]sslseals_public.png