开发者

Is it possible to manipulate a request before IIS assigns that request to a specific site?

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 开发者_JAVA百科site the request belongs to, so I need to change the host header prior to this point.

Possible, or crazy? We're running IIS7.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜