Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thindery's avatar

API Posts in Production not working

I'm pretty stumped so if anyone can point me in a direction I'd really appreciate it.

Everything is working 100% correctly on my local dev machine (Mac). Now when I deploy to a production server my Post requests don't work. I am testing requests via POSTMAN.

  1. GET requests work in dev and production
  2. GET requests know if auth code is valid in dev and production
  3. POST to "rewards" route result in 500 internal server errors in production (dev works)
  4. POST to "test" route result in 404 Method Not Allowed in production (dev works)

/routes/api.php

Route::prefix('v1')->group(function () {
    Route::middleware('auth:api')->group( function () {
        Route::apiResource('rewards', 'API\RewardTransferController');
        Route::apiResource('rewards/customers', 'API\CustomerController');
        Route::get('rewards/customers/bri/{briCustomerNumber}', 'API\CustomerController@getByBriCustomerNumber')->where('briCustomerNumber', '[0-9]{7}');
        Route::post('test', function()
        {
            return "POST SUCCESS!";
        });
    });
});

In the above my /rewards/customers/bri/{briCustomerNumber} route does work in dev and in production.

However, my "test" route does not work in production. The response is json response like this:

{
    "message": ""
}

Additionally a POST request to "rewards" results in an empty response... no JSON format and it is 500 Internal Error.

Anyone know something I can look into to figure out why things aren't working on my production server? My GUI backend works 100% correctly but the test API with POSTMAN doesn't work on POST requests.

0 likes
5 replies
tykus's avatar

Check your logs for the 500 error cause.

What is your production environment (load balancers, HTTP to HTTPS redirection etc.) - your POST request might be redirected without preserving the original request verb?

thindery's avatar

My production environment doesn't have anything fancy on the front (like load balances). It's over at https://www.fortrabbit.com on a server app made for Laravel. It's set to https and that is where I am posting to. Additionally, my backend GUI and everything works just fine in production.

On the test post to the /test route this is the response:

[2018-06-11 16:39:28] production.INFO: api.response {"response":"[object] (Illuminate\Http\JsonResponse: HTTP/1.0 405 Method Not Allowed
Allow:         POST
Cache-Control: no-cache, private
Content-Type:  application/json
Date:          Mon, 11 Jun 2018 16:39:28 GMT

{
    \"message\": \"\"
})"}

Then for my other post to rewards there is no log happening for the 500 response... hmm

thindery's avatar

Okay I figured out what my issue was...

On my dev requests my URLS all end with forward slash "/". So they looked like: http://site.test/api/v1/rewards/ and they worked.

However, in production the trailing forward slash would not work. I had to remove it. Now everything works.

I'm glad I fixed it... but I don't quite understand why this fixed it. Anyone have an explanation why the trailing forward slash needs to be removed?

4 likes
jm-jorgemauricio's avatar

@thindery I also encountered this problem and your tip helped me solve it. Thanks!

I did a bit of digging and the problem seemed to be the .htaccess file that´s shipped with Laravel (in my case, 8) in the public directory.

For a quick fix, just comment these lines:

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
Neeraj1005's avatar

@thindery thanks for your own answer because the same case happens with me in the production level. I also didn't get why?

Please or to participate in this conversation.