0

我们有一个用 ASP.NET 编写的网站。当您打开以下页面时:

http://concert.local/elki/

您可以在末尾看到斜线“/”。我们需要删除它才能拥有:

http://concert.local/elki

我已经尝试了一些事情来使它工作,但它没有帮助。例如,当我在 Global.asax.cs 文件中添加以下代码时:

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>

这将规范的东西放在页眉中。

如何获得以下网址:

http://concert.local/elki

?

4

2 回答 2

1

看看这个答案: url trailing slash and seo

它基本上说谷歌更喜欢尾部斜杠。只需始终如一地编码,您应该会没事的。

于 2013-10-17T06:09:46.433 回答
0

这是谷歌的官方回答。实际上,他们不在乎您是否有斜杠 http://googlewebmastercentral.blogspot.fr/2010/04/to-slash-or-not-to-slash.html

Google 会分别(并且平等地)处理上面的每个 URL,无论它是文件还是目录,或者它是否包含尾部斜杠或不包含尾部斜杠。

于 2014-08-11T11:00:34.190 回答