2013-10-17 32 views
0

我們有一個用ASP.NET編寫的網站。當您打開以下頁面:搜索引擎優化問題並從URL中刪除尾部斜槓

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

+0

爲什麼你需要這個?他們是同一個地址。您的Web服務器可能正在添加額外的斜槓。 – ps2goat

+0

我們需要這個,因爲我的公司支付一些其他人做SEO,那些人要求我們刪除該斜槓? – tesicg

回答

1

退房這樣的回答:url trailing slash and seo

它基本上說,谷歌更喜歡結尾的斜線。只需編碼,你應該沒問題。

+0

非常感謝。您指出的文章非常有用,但我們無法使用帶有斜線的URL。它必須沒有它。 – tesicg

+1

試試這個:http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ – ps2goat

+0

謝謝。我剛剛嘗試按照建議設置IIS 7 部分,但尾部的斜線仍然存在。 – tesicg