【问题标题】:Losing "php://input" after a mod_rewrite在 mod_rewrite 之后丢失“php://input”
【发布时间】:2018-10-06 22:52:09
【问题描述】:

我正在使用 mod_rewrite 将所有 api 调用转发到 apiHandler.php 并关注 .htaccess

RewriteEngine On
RewriteRule ^api/(.*)$ /apiHandler.php

问题是,在apiHandler.php 内部,我正在丢失来自php://input 的数据。

header("Access-Control-Allow-Headers: Content-Type");
header("Content-Type: application/json");

$requestBody = json_decode(file_get_contents("php://input"));
echo json_encode($requestBody);
exit();

每当我使用"http://localhost:80/api/testing" 访问我的api 时,我都会从$requestBody 返回一个空值,但是当我使用"http://localhost:80/apiHandler.php" 时,我会从$requestBody 获得正确的值。

有什么想法吗?

【问题讨论】:

    标签: php mod-rewrite


    【解决方案1】:

    如果其他人遇到此问题或类似问题,请将带有 http 状态代码 307redirect 标志添加到我的重写规则对我有用。我看到了here的建议。

    RewriteRule ^api/(.*)$ /apiHandler.php [R=307]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 2020-07-16
      • 2021-05-25
      相关资源
      最近更新 更多