2012-10-08 120 views
1

我想重定向我的舊地址www.informarea.it/BlogEngine新址www.informarea.it ...重定向blogengine.net(Global.asax中)永久301

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

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")); 

} 

有人能幫助我嗎? 非常感謝 法布里

回答

0

這應該重定向任何查詢的路徑以/ BlogEngine開始與/ BlogEngine刪除相同的網址。

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

優點:

  • 給出了一個301重定向像你要求
  • 保持路徑和查詢字符串的完整以下要求

缺點休息:

  • 需要.net 4.0(第2版。 BlogEngine的7個目標是4.0,所以我不認爲這會是一個問題。)