7

I am working on setting up IIS 7.5 to do reverse proxy for a subdirectory of my site.

Here is the web.config url-rewrite:

<clear />
<rule name="Reverse Proxy to Community" stopProcessing="true">
<match url="^community/qa/(.*)" />
<action type="Rewrite" url="http://xxx.xxx.xxx.xxx/{R:1}" logRewrittenUrl="true" />
</rule>

The ip address points to a networked linux box with apache and a django site.

What I want
All request for /community/qa/* to be redirected to the internal IP specified.

What happens
/community/qa/ - gives 404 (on main IIS server)
/community/qa/questions/ - gives 404 (on main IIS server)
- BUT -
/community/qa/questions/ask/ Works!!!
/community/qa/questions/unanswered/ Works!!

So it seems that it works for all URLs that are 2 subdirectories deep from the starting point.

This just seems odd to me, and I can not figure it out.

Thanks in advance for any help.

1 Answer 1

14

I'm quite sure that in your case problem is in UrlRoutingModule setup. If you look at IIS Modules Setup in Ordered View you will see that UrlRoutingModule is placed higher then Rewrite and ApplicationRequestRouting modules are placed. That means that if you have in your application Route-setup for ASP.NET MVC. This setup will influence requests that come to server intercepting them and forwarding them to MVC-Route-Handlers, not allowing reverse-proxy to do it's job. For example if you have common route setup like this:

routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
  new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

In your case /community/qa/ and /community/qa/questions/ wouldn't work because it would match given Url pattern and would been interpreted as:

/community/ qa/ ---> Controller="community", Action="qa"

/community/ qa/ questions/ ---> Controller="community", Action="qa", Parameter: Id="questions"

If you have no such controllers and actions you will get Http 404 Not Found.

/community/qa/questions/ask/ and /community/qa/questions/unanswered/ would work, because they don't match any UrlRouting pattern in your system.

So simple solution is to add in your UrlRouting configuration (when Web Application starts) ignore rule for your url:

routes.IgnoreRoute("community/qa/{*pathInfo}");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.