0

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.

soliver
  • 319
  • 4
  • 10

1 Answers1

1

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.

soliver
  • 319
  • 4
  • 10
  • "redirected via a SEO-safe HTTP 301 redirect." - This can be resolved by using a 308 HTTP response instead, that instructs the user-agent to preserve the request method across the redirect (as opposed to converting it to GET). However, you shouldn't be POSTing to a URL that is redirected to begin with. – MrWhite May 27 '22 at 14:26