1

Hi I am currently using the below code in my apache httpd.conf file to redirect from HTTP to HTTPS

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

This redirects parameters from a get request but not from a post. From reading on here it looks like this needs to be done using mod_rewrite.

Can somebody help with the amendments I would need to make so that when the link on the left is hit using post params it redirects to the link on the right with the params intact?

Many thanks

Tom

3

2 Answers 2

2

Looks like Apache config? It's a good idea to specify things like that. The tags confirm it though.

That config only runs when they connect on port 443, so it can't redirect from HTTP.

You can't do a 30[12] redirect in response to a POST request and keep the arguments unless you convert the request to a GET and write the arguments into the URL. Not really recommended.

You can proxy the request, but I'm not sure that solves your problem.

If the user has already submitted data via POST over an unencrypted connection, and you care about the encryption, you're probably best to let that request break anyway, so it gets noticed and fixed. You should be fixing your form target, and also making sure that the form itself (or the page with AJAX in it or whatever) is sent to the user over HTTPS.

UPDATE

Given that shawsy has said that the problem is that The browser cannot make HTTPS connections to the server, a redirect is definitely not what's wanted. Rather you want to proxy the request:

<VirtualHost 10.1.2.91:80>
  # http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
  ProxyPass /GladQE/link https://glad-test.com/GladQE/link.do
  ProxyPass /GladQE/retrieve https://glad-test.com/GladQE/retrieve.do
</VirtualHost>

You could alternatively do it with mod_rewrite and RewriteRule.

There are some extra issues to work out if you're changing the domain name, but I think that's not the case here.


Just as an aside, I personally don't like putting host names or IP addresses anywhere except in the server's /etc/hosts file. If you use names in the hosts file like 'web' and 'mysql', which locate services rather than machines, and you refer to those in your apache and other files, then you can move configuration between machines much more easily, knowing that you only have to go over what's in the hosts file.

7
  • Yes, Sorry I didnt mention the code is from httpd.conf file. I also made a mistake on the virtual host tag. I have now ammended to port 80 not 443.
    – shawsy
    Jun 5, 2013 at 14:31
  • Currently the Load balancer solution in place cannot handle ssl. This is why i am forward the request as http and then redirect to https once the correct web server has been hit. Sorry but my knowledge on this is far from average.
    – shawsy
    Jun 5, 2013 at 14:34
  • Then a redirect is definitely not what you want.
    – mc0e
    Jun 5, 2013 at 14:58
  • Do I need to have the mod_proxy.so file in the modules folder? The only files I have in the modules folder are httpd.exp and mod_jk.so
    – shawsy
    Jun 6, 2013 at 10:37
  • you will need mod_proxy. How you go about configuring that varies a bit between different operating systems and distributions.
    – mc0e
    Jun 7, 2013 at 18:10
1

You can use 307 redirect to keep method. From Wikipedia:

In this case, the request should be repeated with another URI; however, future requests should still use the original URI. In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request. For example, a POST request should be repeated using another POST request.

1
  • The best answer.
    – jira
    Jan 23, 2018 at 8:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .