Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirection on Apache (Maintain POST params)

Tags:

I have Apache installed on my server and I need to redirect from http to https. The reason for this is our load balancer solution cannot hand https so requests come in on http and then we transfer them to https using the below lines in the httpd.conf file.

<VirtualHost 10.1.2.91:80>      Redirect 302 /GladQE/link https://glad-test.com/GladQE/link.do </VirtualHost> 

This works fine for GET requests but POST requests will lose the parameters passed on the URL. What would be the easiest way to perform this redirect and maintain POST params?

I need to get from http://glad-test.com/GladQE/link.do to here https://glad-test.com/GladQE/link.do maintaining POST params

Thanks

Tom

like image 205
shawsy Avatar asked Jun 25 '13 10:06

shawsy


People also ask

Can Apache redirects handle post data?

Standard Apache redirects will not be able to handle POST data as they work on the URL level. POST data is passed in the body of the request, which gets dropped if you do a standard redirect.

Can I redirect a POST request to another post?

For instance, a POST request should be repeated using another POST request. Show activity on this post. Standard Apache redirects will not be able to handle POST data as they work on the URL level. POST data is passed in the body of the request, which gets dropped if you do a standard redirect.

How do I redirect a specific URL in Apache?

The Redirect directive lets you execute simple and one-page redirects with Apache. It connects an old URL with a new one by asking the client to fetch the resource again at the new location. The Redirect directive requires at minimum two arguments: the old URL and the new URL.

Do 301 redirects preserve post parameters?

No rediect 30x preserves post parameters Using 301 redirects for general URL rewriting is not the way to go. This is a performance issue (especially for mobile, but also in general), since it doubles the number of requests for your page. Think about using a URL rewriting tool like Tuckey's URLrewriteFilter or apache mod_rewrite.


1 Answers

You can try with the HTTP status code 307, a RFC compilant browser should repeat the post request. Reference: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request. For instance, a POST request should be repeated using another POST request.

To change from 302 to 307, do that:

<VirtualHost 10.1.2.91:80>      Redirect 307 /GladQE/link https://glad-test.com/GladQE/link.do </VirtualHost> 
like image 62
Lorenz Avatar answered Oct 22 '22 12:10

Lorenz