Redirecting POST Data with ProxyPass
It is possible to redirect POST data to a different address through server configuration. Here's how to achieve this using ProxyPass in Apache's .htaccess file:
1. Configure .htaccess:
In the .htaccess file located in the website's root directory, add the following rule:
# Redirect mail posting to index.php RewriteRule send-mail index.php?send-mail [NC,P]
2. Enable ProxyPass:
Ensure that the ProxyPass module is enabled in your server configuration. This can be done by adding the following line to the Apache configuration file (typically httpd.conf):
LoadModule proxy_module modules/mod_proxy.so
3. Edit Form Action:
Change the form's action attribute to the fake address used in the redirect rule:
<form action="/send-mail" method="post">
4. Handle POST Data in index.php:
In your index.php script, use the parse_str() function to extract POST data from the QUERY_STRING variable:
parse_str($_SERVER['QUERY_STRING'], $_POST);
This will make the POST data available to your PHP script, even though the request is being redirected.
The above is the detailed content of How to Redirect POST Data to a Different Address with ProxyPass in Apache?. For more information, please follow other related articles on the PHP Chinese website!