I'm trying to deploy a jetty servlet using ARR and urlrewrite to create a reverse proxy. If I enable "Reverse rewrite host in response headers" then everything seems to work fine. I access the servlet at www.example.com/servlet, the address stays the same in the browser but the servlet is accessed at localhost:8080.

The issue is that this servlet returns 302 redirects depending on get parameters. So for example if I go to www.example.com/servlet?input=cleaning then I will get a 302 redirect which might go to www.cleaningexample.com/howtoclean. The reverse rewrite host rule means that instead of seeing this url the client is returned www.example.com/howtoclean.

I can't set a static outbound rule as I don't know ahead of time which address the 302 redirect may return.

If I disable the reverse rewrite host then the url in the browser changes from www.example.com/servlet to localhost:8080/servlet.

I've tried replacing the host in an outbound rule but I can't find anywhere to get the original location header returned by the servlet to replace the rewritten Location host with.

Is there a way to get this working correctly?

up vote 1 down vote accepted

Did you ever figure this out? I am having the exact same issue. I cannot get both situations to behave correctly. It's either I check the box, and 302 redirects get the response location header overwritten and never work, or I uncheck the box and the HOST header is localhost so the application doesn't fully work.

It's like that checkbox needs to be a little smarter, and say 'if not a 302, do this'. Or I have to add rules/before and after, but I don't think that's going to be possible. :-(

---- 20 minutes later, got really lucky and found the answer.

https://stackoverflow.com/a/14842856/8333628

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost

That command, plus the reverse rewrite host in response headers UNCHECKED seems to work. External redirects work with that box unchecked, and with that command to preserve the host, the downstream app no longer sees localhost:8080 but the original host in the browser address bar. Both work!!!

It's comical that there's just no option in the UI for preserveHostHeader. They just never added the checkbox. :) If you go in the 'configuration editor' in the control panel, you can see it there in the xml schema. So it's a legit, setting they just missed it in the UI options. :(

  • Please rephrase this answer to not start as a question anymore. – Sven Apr 18 at 20:40

I just ran into a very similar issue using IIS as a reverse proxy to another HTTP server I had locally. I had to go to the "Application Request Routing Cache" module. On the right-hand pane there's a "Server proxy settings" link. In that settings dialog there's a "Reverse rewrite host in response headers" checkbox. Unchecking this box fixed my problem.

  • Thanks I'm aware of this I mention the reverse rewrite host in the first paragraph. The problem is that inbound rules then break. – SMC Nov 1 '17 at 17:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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