您可能会考虑另一种方法:
protected void Application_BeginRequest (object sender, EventArgs e){ if (!Request.Url.Host.StartsWith ("www") && !Request.Url.IsLoopback) { UriBuilder builder = new UriBuilder (Request.Url); builder.Host = "www." + Request.Url.Host; Response.Redirect (builder.ToString (), true); }}
但是,这将执行302重定向,因此建议进行一些调整:
protected void Application_BeginRequest (object sender, EventArgs e){ if (!Request.Url.Host.StartsWith ("www") && !Request.Url.IsLoopback) { UriBuilder builder = new UriBuilder (Request.Url); builder.Host = "www." + Request.Url.Host; Response.StatusCode = 301; Response.AddHeader ("Location", builder.ToString ()); Response.End (); }}
这将返回“ 301已永久移动”。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)