Does mod_rewrite work with POST data?

Can you grab a forms POST data and rewrite it or write a new query string based on information in POST data?


I didn’t think so but I just checked Apache’s page for mod_rewrite and didn’t find a POST there (post-processing about the rewrite rules, yes, but not POST). I suspect that there might be some way for your script to read the page headers which would include the POST data - but I’ve never done that.

Anyone else?



Thanks for trying David,

I read that Apache might place POST data into the query string if prompted to do so but can’t find anything about this anywhere. The only direct POST use I have found is in mod_security,about which there is even less information. I am trying to do this without touching the phpBB code and using .htaccess so catching the headers is out (unless I want to add another redirect).

POST date comes in stdin, and you can’t touch it with mod_rewrite.

However, POST request can have QUERY_STRING in addition to POST data.
I’ve used it in some cases. (I don’t think it’s a good thing to do, in general)

If GET method is used for the form, then you can access and transform QUERY_STRING
with mod_rewrite, easily.
But you can’t use GET method for huge data. (Around 4k max, in some OS, I think).

I’m not sure if you can access RAW POST data that is taken from stdin in PHP.
(You can access raw QUERY_STRING, but I don’t think it contains POST data.)
In other normal languages, raw POST data can be accessed and treated in the way you want.

The POST data is sent into the http message body, the query string is sent into the http message header.

There is not way for mod_rewrite to read the http message body content.

Thanks for the confirmation, Andrea!

Carl, the way that I handle that is to POST the form and use hidden fields to stuff information into the $_POST array. That said, the data will show in the source code for your page but you will get it anyway. $_REQUESTS will access $_GET, $_POST and $_COOKIE data. If you’re really trying to hide information, use cookies (after testing that they’re accepted by the user’s browser configuration).



Unfortunately I have to do some type of work around because I don’t think I can convince the phpBB dev team to change this just for my sake :wink: