views:

24

answers:

2

Is it possible to manipulate an inbound request at the IIS level, before it even gets assigned to site on the server?

Essentially, I want to rewrite this --

www.somegenericdomain.com?site=someotherdomain

To this --

www.someotherdomain.com

And I need to do this before IIS picks which site the request belongs to, so I need to change the host header prior to this point.

Possible, or crazy? We're running IIS7.

A: 

You can rewrite, redirect, or proxy requests.

  • Rewrite changes the request, but does not change the site to which it is assigned. With a rewrite you can:

    • return an HTTP error code (503, 404, 401, etc);
    • manipulate the query string or URL path. one example is to transform a query string param into a URL path element. www.server.com/default.aspx?s=foo becomes www.server.com/foo, or vice versa.
    • set headers in the request.
  • Redirect sends back a 301 or 302 response to the browser with an updated address. You can receive a request for www.example.com/foo and respond to the browser with a 302 and an updated address of www.otherdomain.com , etc.

  • Proxy the request. In this case the web server is said to act as a "transparent proxy". It means the initial IIS server can call out to a second server, grab the response, and then package it up back to the original requester.

These three actions are often done in combination. The tools used to perform these actions are called "URL Rewriters". IIS7 has a built-in option from Microsoft (The IIS URL Rewrite Module), and there are third-party options as well, some free and some commercial, for IIS6, IIS7, and other non-Windows web servers. Apache's mod_proxy is the big one for Linux. All of these tools do basically the same kinds of things.


To answer your specific question, NO, you cannot rewrite a request from one domain to another. For web servers, rewrite is a meaningful term, and a URL Rewrite excludes the possibility of a server change.

It is possible though, to transform a request from one server to another, either via redirect or proxy. One of those may actually be what you want, when you ask about "rewriting" a request.

Cheeso
I definitely want to rewrite, not redirect (browser URL needs to stay the same). I did find the URL Rewriting module and have been playing with it, but it doesn't look like it will let me rewrite the "Host" header, which is fundamentally what I need to do. Your proxy idea is interesting...
Deane
I don't know if the IIS Url Rewrite Module does proxies. IIRF does. It's free. http://iirf.codeplex.com.
Cheeso
A: 

Hello, I guess the whole thing is possible, but not in the way of running before IIS. One part of the server even works as a low-level driver. But you may use URL rewriting solutions such as mod_rewrite module of Helicon Ape http://www.helicontech.com/ape/doc/mod_rewrite.htm. Having set the software globally for all the sites, you may get what you need as follows:

RewriteEngine on
RewriteCond %{HTTP_HOST} www.somegenericdomain.com [NC]
RewriteProxy (.*) http://www.someotherdomain.com$1
Slava