我最近完成了将一个非常大的ASPDotNetStorefront站点(许多页面/ URL)从域的wwwroot转移到子域。
出于搜索引擎优化的原因,我想自动301重定向任何&所有以“.aspx”结尾的OLD URL到子域上的新位置。 (除了现在在子域而不是wwwroot之外,所有路径都是相同的)
实施例: OLD URL =“http://www.mysite.com/c-2-some-product-page.aspx”
理想的新网址=“http://store.mysite.com/c-2-some-product-page.aspx”
我需要一些东西来检查请求的页面是否以.aspx结尾,然后重定向到“store”子域。它还应该确保请求的旧页面URL不存在
此网站在Windows主机AppliedI.net上运行
非常感谢
答案 0 :(得分:0)
我想你想在你的global.asax文件中尝试这样的东西
// Untested, but the concept is there.
private void Application_BeginRequest(Object source, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().ToLower().StartsWith(
"http://www.mysite.com/"))
{
HttpContext.Current.Response.Status =
"301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
Request.Url.ToString().ToLower().Replace(
"http://www.mysite.com/",
"http://store.mysite.com/"));
}
}