Simple POST domain rewrite with htaccess and PHP

by | Feb 24, 2017 | WordPress Tweaks

So you’ve finished a big domain name transition, created your htaccess rewrite, and kicked back to celebrate. But wait! Suddenly you realize that all of the third-party applications posting data to your site have stopped working! The realization quickly hits that htaccess redirect rules to different domains always use GET. They are not able to redirect POST requests!

Obviously, the longterm solution is to change all of these third-party applications to POST their data to the new domain URL. But sometimes that is not possible to do right away. In such cases, one simple solution is to write a little PHP relay script on your old domain that will receive all POST requests and post the data over to your new site, returning the result.

To redirect all the old domain traffic to the above rewrite.php script, we’d simply create the following .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ rewrite.php [QSA,L]

And then we can start the celebration. 🙂


Submit a Comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.