Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am experiencing some issues with apache and mod_rewrite. The server I am running is using apache on centos. The same server is running Windows as a virtual machine.

My current setup allows me to access:

http://example.com on the centos server and

http://example.com/windows on the virtual machine using the following configuration:

RewriteEngine On
RewriteRule ^/windows(.*)$ http://192.168.56.2$1 [P]

However, when accessing http://example.com/windows all request get rewritten as GET request therefore any POST data is lost.

Is there anyway for me to retain my POST data?

Any help is greatly appreciated! Thank you.

share|improve this question
    
Do you mean request data in a POST, or query params in the URL? This config will lose query string parameters, but won't touch the contents of a POST. –  Shane Madden Nov 15 '11 at 16:20
    
@ShaneMadden Weirdly enough it leaves query parameters where they are, but the apache server seems to send the browser a 302 redirect. Any ideas how to do the redirect internally? –  Ben Nov 16 '11 at 0:06

1 Answer 1

up vote 1 down vote accepted

What's the 302 look like? There's a few options here: it may be Apache, or the server that's getting proxied to, or an intended behavior of the application that's handling the request on the backend server.

Option A:

Apache will send a 302 to add a trailing slash if it needs to, but since this resource matches a proxy rule, it shouldn't care.

Option B:

If the request is for just http://example.com/windows, then the request gets sent to the backend as http://192.168.56.2 - this needs to have a slash after the IP to be a valid request, so no web server could be blamed for kicking back a 302 to add one.

Option C:

Keep in mind that a redirect isn't necessarily indicative of a failure condition in a POST request - some applications are designed to do it, to prevent accidental double-posts by users. See here from details.


Do some digging in logs and see which it is.

Oh, and your configuration is vulnerable to the vulnerability described in CVE-2011-3368 - a request for http://example.com/windows@192.168.56.100/index.html, for instance, would send the request to http://192.168.56.2@192.168.56.100/index.html - 192.168.56.2 ends up being treated as the user specification, 192.168.56.100 is treated as the host, and an attacker can get to any internal host that your proxy can see.

Try this config - this should both fix trailing slash issues if option B above is the problem, as well as resolving your exposure to the vulnerability:

RewriteRule ^/windows/?(.*?)$ http://192.168.56.2/$1 [P]
share|improve this answer
    
Thank you very much for your long comment. I have figured out a different solution using ProxyPass /windows http://192.168.56.2/ and for now it seems to be working fine. Is there any downside to using the ProxyPass? –  Ben Nov 16 '11 at 3:19
    
@Ben Not at all! It's functionally equivalent to the RewriteRule that I provided, is less computationally expensive, and avoids the vulnerability as well - for some reason I had assumed that you needed to stick to mod_rewrite, or I would have recommended using ProxyPass in my answer. –  Shane Madden Nov 16 '11 at 3:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.