【发布时间】:2023-03-09 21:12:01
【问题描述】:
我的要求是我们的 SEO 专家建议 www.example.com/index.aspx
应加载为 www.example.com 以用于 google index Canonical Issue
我还想提一下,因为共享服务器我们无法访问 IIS 服务器,并且支持人员不太合作。
我尝试了 global.asax 中的以下代码。 Index.aspx 是该站点的默认页面,因此它会引发错误:“500 - 内部服务器错误。”
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
if (oldpath.Contains("index.aspx") == true)
{
HttpContext.Current.RewritePath("http://www.example.com", false);
}
}
//Also tried following
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
if (oldpath.Contains("index.aspx") == true)
{
Response.Redirect"http://www.example.com"
}
}
【问题讨论】:
标签: url-rewriting global-asax rewritepath