【问题标题】:how to make nginx rewirte url from one php to another php如何使 nginx 将 url 从一个 php 重写为另一个 php
【发布时间】:2014-11-03 07:53:23
【问题描述】:

我有一个旧的 Web 应用程序,它使用 get.php 与客户端应用程序交互。现在我们升级了我们的 web 应用程序以使用 laravel 框架,它使用 restful api 作为 url 接口,

我们的服务器使用 nginx,所以我想将旧 url 重定向到新 url,如下所示:

/get.php?update => /update or (index.php/update)

我已经尝试过这些配置。

    location = /get.php?update {
            try_files $uri $uri/ /index.php/update;
    }

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

但似乎当我访问get.php 时,我仍然得到404 error

那么如何使用 nginx 的重写来重定向它呢?

【问题讨论】:

    标签: php .htaccess nginx


    【解决方案1】:

    Nginx location 块与查询字符串不匹配,因此您的尝试将失败。

    试试这个:

    location = /get.php {
        if ($args = update) {
            rewrite ^ /index.php?$query_string last;
        }
    }
    

    但是IF 有点像evil

    【讨论】:

    • 谢谢,我已经成功解决了这个问题,方法是在我的 laravel 控制器中添加了一个 missingMethod 函数,并将它添加到 nginx 的配置文件 location = /get.php { try_files $uri $uri/ /index. php?$query_string;所以我让我的 laravel 控制器决定如何处理 get.php 和选项
    猜你喜欢
    • 2014-10-11
    • 1970-01-01
    • 2023-03-23
    • 2011-01-20
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    相关资源
    最近更新 更多