2012-02-13 94 views
1

我正在使用IIS7和urlMappings將一些網址映射到實際頁面。IIS urlMappings重定向和搜索引擎優化

例子:

<urlMappings> 
     <!-- Remap friendly urls to actual pages: --> 
     <add url="~/help/" mappedUrl="~/content/help/help.aspx" /> 
     <add url="~/news/" mappedUrl="~/content/news/default.aspx" /> 
    </urlMappings> 

這個偉大的工程,如果該URL尾有 '/',例如:

http://www.mysite.com/news/

,但我得到找不到網頁錯誤,如果我這樣做:

http://www.mysite.com/news

I可以添加一個額外的條目,而不是尾隨的'/',以便兩者都映射到同一頁面,但我不想爲SEO做這件事(會認爲它是重複的內容)。

是否有可能得到urlMappings重定向?

例如,這樣的事情:

 <add url="~/help" redirect="~/help/" /> 

如果不是這樣,這將是這樣做的最佳方式?

你認爲谷歌真的會懲罰

http://www.mysite.com/news/

http://www.mysite.com/news

的複製?

回答

0

這裏是我的解決辦法:

我添加兩個條目,有和沒有在頁面末尾的「/」,在web.config中urlMappings

<urlMappings> 
    <!-- Remap friendly urls to actual pages: --> 
    <add url="~/help/" mappedUrl="~/content/help/help.aspx" /> 
    <add url="~/help" mappedUrl="~/content/help/help.aspx" /> 
</urlMappings> 

然後將自身添加以下代碼在Page_Load中:

Dim mappedUrl as string = "/help" 
    If Request.RawUrl.EndsWith(mappedUrl) Then 
     Response.RedirectPermanent(String.Format("~{0}/", mappedUrl)) 
    End If 

這將永久重定向並沒有尾隨「/」到同一頁面末尾的「/」

調用到頁面映射