【问题标题】:NGINX rewrite one URL with parameter to another URL with new parametersNGINX 将一个带参数的 URL 重写为另一个带新参数的 URL
【发布时间】:2017-04-06 22:50:27
【问题描述】:

我想将一个参数为 301 的特定 URL 重定向到另一个具有新参数的特定 URL。

https://www.example.com/index.php?id=329

https://www.example.com/index.php?eID=dd_googlesitemap

我尝试了一些东西,但我认为有几个错误。

location = /index.php?id=329 {
    rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
}

location = /index.php {
    if ($arg_id = "329") {
        rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
    }
}

location = /index.php {
    if ($args ~ "id=329") {
        rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
    }
}

谁能帮忙?

谢谢!

【问题讨论】:

    标签: php nginx parameters url-rewriting typo3


    【解决方案1】:

    /index.php URI 由location ~ \.php$ 块处理,包括将文件名发送到 PHP 执行的所有必要语句。如果您要为/index.php 创建一个新的location,您还需要复制这些语句。

    例如:

    location = /index.php {
        if ($arg_id = "329") {
            return 301 /index.php?eID=dd_googlesitemap;
        }
        ... php statements ...
    }
    location ~ \.php$ {
        ... php statements ...
    }
    

    或者,检查 URI进入 location 块之前。

    例如:

    server {
        ...
        if ($request_uri = "/index.php?id=329") {
            return 301 /index.php?eID=dd_googlesitemap;
        }
        ...
    }
    

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      相关资源
      最近更新 更多