Home >Backend Development >PHP Tutorial >How to Redirect POST Data with .htaccess?
Redirecting POST Data in .htaccess
A common practice in web development is to redirect all requests to a central index page, where PHP is utilized to parse the URI and display the appropriate content. However, a common challenge arises when attempting to submit POST data to a specific address while maintaining the redirect.
Consider the following scenario:
# redirect mail posting to index RewriteRule send-mail index.php?send-mail [NC,L]
With this rule in .htaccess, any request to "/send-mail" will be silently redirected to "index.php?send-mail". While this allows for the proper processing of the GET parameter, it unfortunately discards any POST data that was intended for the targeted address.
To address this issue, the flag "P" (Pass-Through) can be used within the rewrite rule:
# redirect mail posting to index RewriteRule send-mail index.php?send-mail [NC,P]
The "P" flag instructs the module to pass the request to the proxy intact, allowing the POST data to be preserved.
The above is the detailed content of How to Redirect POST Data with .htaccess?. For more information, please follow other related articles on the PHP Chinese website!