【问题标题】:Redirect permanently 301 in blogengine.net (global.asax)在 blogengine.net (global.asax) 中永久重定向 301
【发布时间】:2012-10-08 15:04:16
【问题描述】:

我想将旧地址 www.informarea.it/BlogEngine 重定向到新地址 www.informarea.it...

*我的 blogengine.net 的 global.asax 是 *

void Application_BeginRequest(object source, EventArgs e)
{
    HttpApplication app = (HttpApplication)source;
    HttpContext context = app.Context;

   // Attempt to perform first request initialization
    FirstRequestInitialization.Initialize(context);
}

*我可以永久应用重定向代码吗? *

if (app.url.ToString().ToLower().Contains("http://www.informarea.it/BlogEngine")) 
 {

     HttpContext.Current.Response.Status = "301 Moved Permanently";   

     HttpContext.Current.Response.AddHeader("Location",url.Replace("http://www.informarea.it/blogengine", "http://www.informarea.it"));

}

有人可以帮助我吗? 非常感谢你 法布里

【问题讨论】:

    标签: blogengine.net


    【解决方案1】:

    这应该将路径以 /BlogEngine 开头的任何查询重定向到删除 /BlogEngine 的相同 url。

    if(Request.Url.PathAndQuery.StartsWith("/BlogEngine", StringComparison.OrdinalIgnoreCase)) {
        Response.RedirectPermanent(Request.Url.PathAndQuery.Substring(11), true);
    }
    

    优点:

    • 按照您的要求提供 301 重定向
    • 为以下请求保持路径和查询字符串的其余部分不变

    缺点:

    • 需要 .net 4.0(BlogEngine 2.7 版的目标是 4.0,所以我认为这不会成为问题。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 2013-07-17
      • 1970-01-01
      • 2012-05-31
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多