在blogengine.net中永久重定向301(global.asax)

时间:2012-10-08 15:04:16

标签: blogengine.net

我想将旧地址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"));

}

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

1 个答案:

答案 0 :(得分:0)

这应该将路径以/ 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,所以我认为这不会是一个问题。)
相关问题