Redirecting GET as POST

I have a website that navigates via a form "POST"  (not GET)
method.  So you can't have a naked URL that drops a customer
on an item page.

When I go to do promotions it is impossible to have a
link right to a particular item

I am looking for a way (a Script ?)
That parses a regular (GET) hyperlink which contains elements
for the POST form.  

When the server receives the request it would cause the browser to
redirect using the elements provided as a POST request
as though the customer was normally navigating my site.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
What you're looking for is a router.  I use the slim framework.  It has a very small footprint and is very easy to use, including receiving all kinds of HTML requests and showing the appropriate content (or redirecting as necessary): |

Please check it out and I'll be happy to answer any queries you have.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve BinkCommented:
While I have no doubt a router would work for this, my first instinct says it might be a little heavy-handed.  If all you need is to translate GET values into POST values, most languages can do this with a small bit of code inserted into the right place.  

What language/platform are you using for your current site?
RobOwner (Aidellio)Commented:
So in Slim your code would look like the following but I'm guessing at what you want and it's an example only of showing you how you can manipulate the data and requests as they come in

$app = new \Slim\Slim();

$app->post('/search', function () {
  $terms = $app->request->params('search_terms');
  // do something with the search terms (I haven't covered sanitizing input from the user and using filter_var() but you should USE it)
  $results_url = search_for_products($terms);  // your function


Open in new window

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

RobOwner (Aidellio)Commented:
Steve does make a good point... when using any additional framework or library you want to make sure that you're not "bloating" your site with unnecessary code.  And of course I've assumed PHP which would be a deal-breaker if you're not using it! :)

One of the main reasons I use a router is for SEO.  Being able to take GET routes and essentially do what you can with POST and vice-versa but having "friendly" urls will help your site rank well in the search engines.
Shalom CarmelCTOCommented:
I am not so sure that slim will work here.

If I understand correctly, the question is about sending a 3xx redirection back to the client in response to a GET request, that will force the client to POST and get to the real location.

As far as I know this is not how HTTP works.

The only trick that may work is dynamic construction of a POST form, using the GET query string values in hidden fields, and use setTimeout to auto-submit the form to the target location.
RobOwner (Aidellio)Commented:

You're right, that's not how HTTP works.  However, my suggestion revolves around not doing it that way but rather take a request to a URL and based on the request type (GET or POST)  and perform the necessary action (as long as the GET request satisfies certain criteria).  

$app = new \Slim\Slim();

$app->map('/foo/bar(/:id(/:product(/:size)))', function($id, $product, $size)  use ($app) {
	// this will receive requests to the URL "/foo/bar"
	// we can configure the logic here to accept either POST or GET but perform the same action if requirements are met
	if ($app->request->isGet()) {
		// check that id, product, size all are valid and if they are, do the same action as POST
		if ($valid) {
			$app->render('submitPage.php', array('id'=>$id, 'product'=>$product, 'size'=>$size);
		else {
			// not valid so redirect
	else if ($app->request->isPost()) {
		// do some action here
		$app->render('submitPage.php', $app->request->post());
	else {
		// not a valid request so redirect
})->via('GET', 'POST');


Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.