Redirecting POST Requests Using `htaccess`

Context: Redirect XHR POST requests to another WordPress API on a sub-domain using htaccess and maintaining POST data.

Note

Using a 307 compares to 302 but forces the client to preserve $_POST data. Similarly, 308 compares to 301 but with $_POST data preservation. Using temporary redirect makes more sense since an API request is being redirected instead of the new location of a static resource.

When comparing 308 and 307, a 307 is older and better supported. Furthermore, in the context where these conclusions are gathered from, response times are ~1200ms versus ~250ms, respectively. Values are averages of each redirect type tested three times.

Solution

.htaccess code for redirecting POST requests to a subdomain using 307 code. Edit accordingly.

Redirect 307 /request/from/static/frontend https://cms.website.com/target/url

References

  1. Information on RFC 7538 >> RFC Editor
  2. Redirect request with POST data using .htaccess | Kalpesh Mehta
  3. php – Is it possible to redirect post data? – Stack Overflow
  4. Redirecting API requests and post data using htaccess | Jay Gould

Did this solve your issue?