2

I am using a mod_rewrite to forward all api calls to apiHandler.php with the follow .htaccess:

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

The problem is, inside apiHandler.php, I'm losing the data from 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();

Whenever I hit my api with: "http://localhost:80/api/testing" I get back a null from $requestBody, but when I use "http://localhost:80/apiHandler.php", I get back the correct value from $requestBody.

doesn't work works

Any ideas?

Jacob
  • 439
  • 6
  • 19

1 Answers1

0

If anybody else is having trouble with this or a similar problem, adding the redirect flag, with http status code 307, to my rewrite rule worked for me. I saw the suggestion here.

RewriteRule ^api/(.*)$ /apiHandler.php [R=307]
Jacob
  • 439
  • 6
  • 19