We have the following requirements:
我们有以下要求:
-
redirect http://host1.domain.com/resource1/* to https://host2.domain.com/resource1/* (retaining everything including /resource1/* and query strings, etc.)
将http://host1.domain.com/resource1/*重定向到https://host2.domain.com/resource1/*(保留所有内容,包括/ resource1 / *和查询字符串等)
-
do NOT redirect http://host1.domain.com/resource2/* at all
不要重定向http://host1.domain.com/resource2/*
-
we cannot use Application Request Routing
我们不能使用应用程序请求路由
IIS 7.5
We can use either redirect or rewrite, whichever works. It seems like setting up an inbound rewrite rule with the 'reverse proxy' option (which creates a condition using an Input with {CACHE_URL}) comes close, but I cannot get it to work with a Pattern in the 'Match URL' section of /resource1/*. Redirect seems to enable redirecting a resource to another resource on the same host only, not on a different host.
我们可以使用重定向或重写,无论哪种方法都有效。看起来像使用'反向代理'选项设置一个入站重写规则(使用带有{CACHE_URL}的输入创建一个条件)接近,但我无法使用它来处理“匹配URL”部分中的模式。 /资源1 / *。重定向似乎只能将资源重定向到同一主机上的另一个资源,而不是在不同的主机上。
How can we achieve this?
我们怎样才能做到这一点?
1 个解决方案
#1
You can use URL Rewrite for that. Just add in your web.config of your application something like below where it is adding a condition to match only the host name (host1.domain.com) and matching using regular expressions the resource1 and passing that to the action:
您可以使用URL Rewrite。只需添加您的应用程序的web.config,如下所示,它添加条件以仅匹配主机名(host1.domain.com)并使用正则表达式匹配resource1并将其传递给操作:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect resource1" stopProcessing="true">
<match url="resource1/.*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^host1.domain.com$" />
</conditions>
<action type="Redirect" url="https://host2.domain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
#1
You can use URL Rewrite for that. Just add in your web.config of your application something like below where it is adding a condition to match only the host name (host1.domain.com) and matching using regular expressions the resource1 and passing that to the action:
您可以使用URL Rewrite。只需添加您的应用程序的web.config,如下所示,它添加条件以仅匹配主机名(host1.domain.com)并使用正则表达式匹配resource1并将其传递给操作:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect resource1" stopProcessing="true">
<match url="resource1/.*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^host1.domain.com$" />
</conditions>
<action type="Redirect" url="https://host2.domain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>