I have a website where all requests are redirected silently (via .htaccess
) to index.php
and then PHP is used to show the correct page (by parsing the REQUEST_URI
).
I was wondering if it's possible to submit POST data to a fake address too?
I've currently got my form like so...
<form action="/send-mail" method="post">
And my .htaccess
rule is...
# redirect mail posting to index RewriteRule send-mail index.php?send-mail [NC,L]
My index.php
checks isset($_GET['send-mail'])
which works fine.
This however seems to drop off all the POST data that should be sent to it.
Is there a way to keep the post data? I don't want to use GET because it can't send as much information, though it might not be an issue with a simple inquiry form.
Here is my .htaccess
for redirecting to index.php
# serve files and dirs if they exist please, otherwise send to index RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php
You can redirect as many people's post as live at the address. But remember that if this is more than eight people you'll need to come into your local Post Office branch and we'll help you get your application sent off.
POST: A form is sent to the server with a post-request and an entry in the database is changed. Redirect: After a post request, the correct webpage with the changed data is delivered to the client using the redirect instruction (HTTP 303). GET: The client requests a confirmation page.
Try this:
# redirect mail posting to index RewriteRule send-mail index.php?send-mail [NC,P]
"P" acts like "L" in that it stops processing rules but it also tells the module that the request should be passed off to the proxy module intact (meaning POST data is preserved).
You should be able to simply redirect to index.php
, and then in that script, access $_SERVER['REQUEST_URI']
to see the original request, with "send-mail" intact.
By the way, "can't send as much information" is not the reason to use POST. The reason to use POST is that the request will modify data on your site, instead of simply retrieving data.
Suppose you put a hyperlink on your page with a GET request like "/delete_user?id=1234
," and then some search engine innocently follows the link as it's indexing your site. That's why GET requests are not good for requests that modify data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With