Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite rewritten URLs and the POST method

Using forms that POST data to a rewritten URL

         

hbrynjar

6:33 pm on Jul 10, 2006 (gmt 0)

10+ Year Member



Hi all,

I have the following URL:

example.com/data/123/

mod_rewrite actually serves up

example.com/path/to/file.php?id=123

(this is an internal redirect, so the normal http 200 OK code is returned with the original URL)

So far, your classic use of mod_rewrite to beautify URLs.

What I want to do now is to have a form that POSTs data to the rewritten URL; i.e. method="post" action="data/123/"

It seems that this is not possible with mod_rewrite..
when you POST to the rewritten URL, mod_rewrite serves up the content
from the underlying page, but the POST data is not received by that page, so in effect a POST request for URL 1 becomes a
GET request for URL 2.

Is there anyway for POST data to be passed on to a page that
is hidden behind a rewritten URL?

I hope the above is clear enough :)
- Hugo

jdMorgan

3:22 pm on Jul 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I *internally rewrite* many POSTs with no problems. However, if your POST invokes an *external redirect*, then the client may change the request method from POST to GET.

You might want to use a server headers checker, such as Mozilla's "Live HTTP Headers" extension for Firefox, Mozilla and Seamonkey, to track the entire POST process and see if there's an unexpected redirect getting invoked by some other rewrite rules or mod_alias directives.

Jim

hbrynjar

2:41 pm on Jul 16, 2006 (gmt 0)

10+ Year Member



Thanks for the reply JDMorgan.

Turns out I was wrong, the underlying page WAS receiving
the POST data, the prob was a logic error in my PHP script.

So looks like you can send both GET and POST data to a
page via mod_rewrite.

- Hugo