SEO问题并从URL中删除尾部斜杠
我们有一个用ASP.NET编写的网站。打开以下页面时: 您可以在末尾看到斜杠“/”。我们需要将其删除,以便: 我试过一些方法让它起作用,但没用。例如,当我在Global.asax.cs文件中添加以下代码时:SEO问题并从URL中删除尾部斜杠,seo,Seo,我们有一个用ASP.NET编写的网站。打开以下页面时: 您可以在末尾看到斜杠“/”。我们需要将其删除,以便: 我试过一些方法让它起作用,但没用。例如,当我在Global.asax.cs文件中添加以下代码时: protected void Application_BeginRequest(Object sender, EventArgs e) { if (HttpContext.Current.Request.Url.ToString().Contains("http://concer
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://concert.local/elki/", "http://concert.local/elki"));
}
}
出现以下错误:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
还有以下代码:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentHead">
<link rel="canonical" href="http://concert.local/elki" />
</asp:Content>
查看以下答案:
它基本上说谷歌更喜欢后面的斜杠。只要代码保持一致,就可以了。这是谷歌的官方答案。实际上,他们并不在乎你是否有一个尾随斜杠
谷歌将上述每个URL分别(平等)对待,而不考虑
无论是文件还是目录,或者包含尾部斜杠或
它不包含尾部斜杠
你为什么需要这个?他们是同一个地址。您的web服务器可能正在添加额外的斜杠。我们需要这样做,因为我的公司支付其他人做搜索引擎优化,这些人要求我们删除斜杠?非常感谢。你给我写的文章真的很有帮助,但是我们不能使用带有尾随斜杠的URL。它必须没有它,谢谢。我刚刚尝试按照建议设置IIS7部分,但后面的斜杠仍然存在。