【问题标题】:IIS rewrite rule to replace sub domain url to different url on same domainIIS 重写规则以将子域 url 替换为同一域上的不同 url
【发布时间】:2017-11-01 03:58:38
【问题描述】:

只有当下面的 url 包含 '/reports' 时,我才想匹配模式,如果是,那么下面的 url :
https://test.website.com/reports/abc/sample.PDF

只能用子域替换,例如:
https://test2.website.com/reports/abc/sample.PDF

无需更改额外的参数或页面名称。
此 url 内容可以是动态的,我们无法在规则中修复硬编码:reports/abc/sample.PDF

【问题讨论】:

    标签: asp.net iis url-rewriting


    【解决方案1】:

    使用 Global.asax 上的 BeginRequest,检查您的请求路径并采取相应措施 - 这是基于您的问题的示例。

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;    
        string cTheFile = HttpContext.Current.Request.Path;
    
        if (cTheFile.Contains("/reports/") && cTheFile.Contains("https://test."))
        {
            app.Response.Redirect(Request.RawUrl.Replace("https://test.","https://test2."), true);
            return;     
        }
    }
    

    请注意避免此处出现无限循环。

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 2019-08-22
      • 2015-05-11
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多