我們有一個用ASP.NET編寫的網站。當您打開以下頁面:搜索引擎優化問題並從URL中刪除尾部斜槓
你可以看到「/」結尾的斜線。我們需要以有其刪除:
我已經嘗試了一些東西,使其工作,但它並不能幫助。例如,當我的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>
這會在頁眉中放入規範的東西。
我怎樣可以得到以下網址:
?
爲什麼你需要這個?他們是同一個地址。您的Web服務器可能正在添加額外的斜槓。 – ps2goat
我們需要這個,因爲我的公司支付一些其他人做SEO,那些人要求我們刪除該斜槓? – tesicg