müntekim
müntekim

Reputation: 21

Php file_get_contents returning empty result

I'm trying to receive posted (application/json) data to my Php project from using API.

My Php project file located there:

v1/project/index.php

$request = file_get_contents('php://input');

When I use API url like this :

[POST] localhost/v1/project/

It is working. But:

[POST] localhost/v1/project

Not working. I want to share this API without slash on end of URL. How can I fix it?

Upvotes: 1

Views: 160

Answers (1)

müntekim
müntekim

Reputation: 21

Thank you all, It solved by .htaccess redirection (Google: non-slash to slash redirection) .

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

</IfModule>

Upvotes: 1

Related Questions