1

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?

2
  • just use .htaccess redirection Commented Jul 3, 2021 at 10:45
  • 1
    That's a HTTP server config, with localhost/v1/project you try to post to file project whereas localhost/v1/project/ look for index in project directory Commented Jul 3, 2021 at 12:19

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.