【问题标题】:Rewrite all PHP urls to a specific url in nginx将所有 PHP url 重写为 nginx 中的特定 url
【发布时间】:2018-02-21 09:04:13
【问题描述】:

如何将所有 PHP 请求重写为单个特定的 url?

例如这些网址

https://somesite.com/thing.php

https://somesite.com/dir/(包含 index.php)

会被重定向到这个: https://somesite.com/dir/someotherthing.php

我还想保持客户端 URL 不变:

例如,https://somesite.com/thing.php 应该仍然是相同的 URL,而不是立即更改为 https://somesite.com/dir/someotherthing.php

另一个问题,当我这样做时,PHP 中的$_SERVER['REQUEST_URI'] 仍然是客户端的请求 URL 吗?如果没有,我如何将其传递给https://somesite.com/dir/someotherthing.php

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    如果不通过服务器端触摸客户端 URL,您将无法重定向客户端。

    为此使用 AJAX。您正在寻找的行为在某些方面类似于 SPA 应用程序与 API 交互的方式。

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 2021-01-06
      • 2012-08-04
      • 2022-01-14
      相关资源
      最近更新 更多