0

我创建了两个站点,一个在默认站点的 80 端口上,另一个在 786 端口上,现在我希望如果用户打开 url http://myurl.com/Application,它应该打开http://myurl。 com:786/应用程序。我已经安装了 IIS 7.5 重写模块。我尝试了不同方式的代码,例如

<rule name="Red" stopProcessing="true">
        <match url=".*" />
    <conditions logicalGrouping="MatchAll">
                          <add input="{HTTP_HOST}" pattern="www.myurl.com/Application" />

             </conditions>

        <action type="Rewrite" url="http://{HTTP_HOST}:786/{R:0}" />
    </rule>
4

2 回答 2

0

我认为它喜欢 301 永久重定向。您可以使用 HttpModule 来执行此操作。

public class CustomHttpModule : IHttpModule
{

    private HttpApplication app;

    public void Init(HttpApplication context)
    {
        app = context;
        app.AuthorizeRequest += App_AuthorizeRequest;
    }

    public void App_AuthorizeRequest(object sender, EventArgs e)
    {
        HttpRequest req = app.Request;
        string path = req.Path;

        // if starts with http://{HTTP_HOST}
        if (path.StartsWith("http://{HTTP_HOST}", true, CultureInfo.CurrentCulture))
        {
            string redirectUrl = path.Replace("http://{HTTP_HOST}", "http://{HTTP_HOST}:786");
            app.Response.StatusCode = 301;
            app.Response.AddHeader("Location", redirectUrl);
            app.Response.End();
        }
    }

    public void Dispose()
    {

    }
}

此外,您需要在 system.webserver 节点和 system.web 节点中配置此 HttpModule。

于 2012-08-08T02:25:25.050 回答
0
<add input="{REQUEST_URI}" matchType="Pattern" pattern="^/Application$" ignoreCase="true" negate="false" />

this can only resolve the issue.

于 2012-08-12T21:10:55.007 回答