2012-02-13 92 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 

这将永久重定向并没有尾随“/”到同一页面末尾的“/”

调用到页面映射