【问题标题】:Nginx rewrite rule to redirect from requested url to specific urlNginx 重写规则从请求的 url 重定向到特定的 url
【发布时间】:2019-05-17 22:55:40
【问题描述】:

我正在尝试从请求的 html 文件重定向到特定位置。

例如:

来自

https://example.com/cars/description/ferrari-1-1532.html

https://example.com/car/catalog/ferrari.html

我试过这个配置

location /cars/description/*.html {
     rewrite ^(.*)$ https://examples.com/car/catalog/request_filename redirect;
}

但它不起作用。

【问题讨论】:

  • 如何确定具体的URI?它总是第一个词吗?还是您需要一张地图来翻译每个单独的链接?

标签: regex linux nginx url-rewriting


【解决方案1】:

此位置应将所有对/cars/description 目录中的html 文件的请求重定向到此url https://examples.com/car/catalog/request_filename

location ~* /cars/description/(.+\.(html))$ {
     rewrite ^(.*)$ https://examples.com/car/catalog/request_filename redirect;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 2016-12-03
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    相关资源
    最近更新 更多