Nginx位置中的Match返回空$ 1,尽管重定向有效

时间:2018-09-21 23:36:31

标签: regex nginx

我是Nginx的新手,我需要永久重定向这样的URL:

https://www.mydomain/index.php/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/home-form/index.html

像这样的另一个人:

https://www.mywebsite.ext/mars/2015/mypage.php?foo=1&bar=0

我尝试在服务器{...}中使用的location指令如下:

https://www.mywebsite.ext/earth?year=2015&foo=1&bar=0

一切正常,但是$ 1为空,即在上面的示例中,重定向实际产生的URL为:

location ~ ^/mars/([0-9]+)/mypage.php {
    return 301 $scheme://$server_name/earth?year=$1&$args;
}

(“ year”的值应改为“ 2015”)

我做错了什么?我如何实现目标?

1 个答案:

答案 0 :(得分:1)

如上所述,您可以改用命名捕获组:$year,然后在重定向中使用location ~ ^/mars/(?<year>[0-9]+)/mypage.php { return 301 $scheme://$server_name/earth?year=$1&$args; } 变量。

import numpy as np
from scipy import ndimage, interpolate, optimize

img = ndimage.io.imread('VJQwQ.png')
# b&w
img = img[..., 0]
# cut "white letterbox"
img = img[:, np.where(np.any(img!=255, axis=0))[0]]

# setup interpolator for off grid pixel values
x, y = img.shape
x, y = (np.arange(z) - (z-1)/2 for z in (x, y))
intr = interpolate.RectBivariateSpline(x, y, img, kx=3, ky=3)
s = np.arange(-50, 51)

# setup line sections
# for simplicity we assume the peak is in the center
def at_angle(phi):
    def f(s, shift=0):
        x, y = np.cos(phi)*s, np.sin(phi)*s
        return intr(x, y, grid=False) - shift
    return f

# example
phi = np.pi/3
f = at_angle(phi)
mx = f(0)
left = optimize.brentq(f, -50, 0, (mx/2,))
right = optimize.brentq(f, 0, 50, (mx/2,))

# plot it
from matplotlib import pylab
pylab.plot(s, f(s))
pylab.plot([left, left], [0, mx])
pylab.plot([right, right], [0, mx])
pylab.plot([-50, 50], [mx/2, mx/2])
pylab.savefig('tst.png')