在nginx重写中从uri中删除一个hypen和word

时间:2017-07-27 07:26:31

标签: nginx

实际链接结构如下:

domain.com/abc/xyz/lmn/1.0.0-alpha/abc.html 我们想要的是重定向到

domain.com/abc/xyz/lmn/1.0/abc.html

在nginx中使用重写

如何在nginx中完成此操作?

由于

2 个答案:

答案 0 :(得分:0)

这样的东西?我不确定其他要求是什么,但如果它只是一个静态网址它应该工作。

load

答案 1 :(得分:0)

如果您有很多这些,请查看map指令。

但无论如何,我的建议是生成一个简单的页面,告诉用户他们正在寻找的版本已经过时,而且新版本可用,而不是进行自动重定向:

location /abc/zyz/lmn/1.0 {
    rewrite ^(/abc/zyz/lmn/1\.0)(?:\.0-alpha)(abc.html)$ $1$2 break;
    return 404
        "<!DOCTYPE html><title>404 Not Found: $request_uri</title>
         <h1>404 Not Found: $request_uri</h1>
         <h2>The version you're seeking is outdated.
         Try <a href='$uri'>$uri</a> instead.</h2>"
}