r/PHPhelp • u/Double-Bed313 • Sep 04 '25
problem file_get_contents("php://input", true) that does not read any data if / does not end url
Hello,
I created an api rest and i manage to retrieve data with
file_get_contents("php://input", true)
If I call the api with postman with / at the end of url it works well.
But if I do not put the / at the end of the url, file_get_contents("php://input", true) does not get any data.
Does anyone know how I could solve this problem ?
Many many thanks in advance.
4
Upvotes
View all comments
Show parent comment
1
u/allen_jb Sep 04 '25
Check for Apache RewriteRule's that have an R flag, which forces a redirect.
Either remove the external redirect (make it an internal rewrite that doesn't change the URL on the browser), or tell it to use HTTP status 308 (redirect with unchanged method and body)
The other Apache directive's that may cause this are Redirect and RedirectMatch - see the documentation for how to specify the status code for those.
These may be in the main apache config (possibly the site / virtualhost specific config file if there is one), or a .htaccess file.
The other possibility is that the redirect is implemented in the application code. For "modern frameworks" look at the routing middleware configuration.