phpapi.htaccesspostexact-online

Can a POST follow a redirect using file_get_contents('php://input');?


I am building a webhook for Exact Online. I registered my webhook subscription url as: https://www.example.com/webhooks/exact/orders/

In .htaccess I rewrite this url:

Options +FollowSymlinks
Options -MultiViews

RewriteEngine on

RewriteRule ^webhooks/exact/orders/$                /webhooks/exact-orders.php [NC,QSA,L]

In the php file I echo the post input:

echo file_get_contents('php://input');

When I test this with postman it does not output anything but when I change the url to https://example.com/webhooks/exact-orders.php in postman it works.

So the post is lost when the url is rewritten. Is there a way to prevent this or do I have to change my webhook subscription url?

I am using the same rewrite rule for webhooks from other companies and they work fine.


Solution

  • After some testing I found out that the problem had nothing to do with the redirect from /webhooks/exact/orders/ to webhooks/exact-orders.php

    The POST was lost because of the redirect from https://www. to https://

    In the server settings I found a setting called 'Prefered domain'. It explained:

    Select the URL (either with or without the www. prefix) to which site visitors will be redirected via a SEO-safe HTTP 301 redirect.

    When I switched the prefered domain to 'None' the problem was solved.

    As an alternative solution I could change my webhook subscription to an url without the www. prefix

    I hope this wil help someone in the future.