我在 IIS 中找到了 HTTP 重定向功能,但我只能将所有传入请求重定向到特定目标。是否可以在 IIS 中将传入请求重定向到特定 URL?例如:
my.domain.com/blog/about -> other.domainxyz.com/site/about
my.domain.com/blog/post/5 -> other.domainxyz.com/site/5
更新
web.config 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="home" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="http://yojimbo87.github.com/" />
</rule>
<rule name="about" stopProcessing="true">
<match url="^Blog/About$" />
<action type="Redirect" url="http://yojimbo87.github.com/about/about.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
尽管存在 HTTP 重定向,但我还没有在角色服务中找到 URL 重写模块。
答案1
此规则将特定的传入请求重定向到特定的 URL:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect Specific Page" stopProcessing="true">
<match url="^blog/post/5$" />
<action type="Redirect" url="http://other.domainxyz.com/site/5" />
</rule>
</rules>
</rewrite>
</system.webServer>
更新: 我已将它们合并在一起 - 只需用真实的 URL 进行更新即可:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="home" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="http://yojimbo87.github.com/" />
</rule>
<rule name="about" stopProcessing="true">
<match url="^Blog/About$" />
<action type="Redirect" url="http://yojimbo87.github.com/about/about.html" />
</rule>
<rule name="Redirect Specific Page" stopProcessing="true">
<match url="^blog/post/5$" />
<action type="Redirect" url="http://other.domainxyz.com/site/5" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>