'How to set HTTP OPTIONS Method in Cloudflare only to allow GET and POST

I have Cloudflare free SSL enabled on a website and I need to change the HTTP OPTIONS Method to allow only GET and POST.

I've used this command in SSH to check what methods are available:

curl -X OPTIONS https://example.com -I

and the relevant result is:

...
*  issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0xxxx)
> OPTIONS / HTTP/2
> Host: example.com
> user-agent: curl/7.68.0
> accept: */*
...

From "accept: /" I understand that all methods are allowed and I would like to change this.

I have tried to edit the .htaccess file on the server and added

RewriteEngine on
RewriteCond %{THE_REQUEST} !^(POST|GET)\ /.*\ HTTP/1\.1$
RewriteRule .* - [F]

and it didn't seem to work and I think it may be something I can fix in Cloudflare but have no clue how should I do this. Does anyone know if this can be done and can point me in the right direction?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source