我想将旧地址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"));
}
有人可以帮帮我吗? 非常感谢你 法布里
答案 0 :(得分:0)
这应该将路径以/ BlogEngine开头的任何查询重定向到删除了/ BlogEngine的同一URL。
if(Request.Url.PathAndQuery.StartsWith("/BlogEngine", StringComparison.OrdinalIgnoreCase)) {
Response.RedirectPermanent(Request.Url.PathAndQuery.Substring(11), true);
}
优点:
缺点: