是否可以在 IIS 将请求分配给特定站点之前对该请求进行操作?
是否可以在将入站请求分配给服务器上的站点之前在 IIS 级别对其进行操作?
本质上,我想重写这个 -
www.somegenericdomain.com?site=someotherdomain
到这个 -
www.someotherdomain.com
我需要在 IIS 选择请求所属的站点之前执行此操作,因此我需要在此之前更改主机标头。
有可能,还是疯狂?我们正在运行 IIS7。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重写、重定向或代理请求。
重写更改请求,但不会更改分配到的站点。通过重写,您可以:
重定向将包含更新后地址的 301 或 302 响应发送回浏览器。您可以接收对 www.example.com/foo 的请求,并使用 302 和 www.otherdomain.com 的更新地址等响应浏览器。
代理该请求。在这种情况下,网络服务器被称为“透明代理”。这意味着初始 IIS 服务器可以调用第二个服务器,获取响应,然后将其打包回原始请求者。
这三个动作常常结合起来进行。用于执行这些操作的工具称为“URL 重写器”。 IIS7 有一个来自 Microsoft 的内置选项(IIS URL 重写模块),并且有还有第三方选项,一些是免费的,一些是商业的,适用于 IIS6、IIS7 和其他非 Windows Web 服务器。 Apache 的 mod_proxy 是 Linux 上最重要的一个。所有这些工具基本上都做同样的事情。
要回答您的具体问题,不,您不能重写从一个域到另一个域的请求。对于 Web 服务器,重写是一个有意义的术语, URL 重写排除了服务器更改的可能性。
不过,可以通过重定向或代理将请求从一台服务器转换到另一台服务器。当您询问“重写”请求时,其中之一可能实际上就是您想要的。
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:
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.
我想整个事情是可能的,但不是以在IIS之前运行的方式。服务器的一部分甚至充当低级驱动程序。
但您可以使用 URL 重写解决方案,例如 Helicon Ape 的 mod_rewrite 模块 http://www. helicontech.com/ape/doc/mod_rewrite.htm。为所有站点全局设置软件后,您可能会得到您需要的内容,如下所示:
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: