从域到www.domain的全局301重定向 [英] Global 301 redirection from domain to www.domain
本文介绍了从域到www.domain的全局301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用Global.asax的begin请求重定向所有内容,
could i use the begin request of Global.asax to redirect everything,
从 mydomain.domain 到 www.mydomain.domain ?
如果这是真的,我该怎么办?
If this one is true, how can i do that?
推荐答案
protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
string currentUrl = HttpContext.Current.Request.Path.ToLower();
if(currentUrl.StartsWith("http://mydomain"))
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", currentUrl.Replace("http://mydomain", "http://www.mydomain"));
Response.End();
}
}
这篇关于从域到www.domain的全局301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文