我正在使用IIS7和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>
如果网址有一个尾随的“/”,则效果很好,例如:
但如果我这样做,我会发现找不到页面错误:
我可以添加一个没有尾随'/'的额外条目,以便两者都映射到同一页面,但我不想为SEO做这个(会认为它是重复的内容)。
是否可以让urlMappings重定向?
例如,像这样:
<add url="~/help" redirect="~/help/" />
如果没有,那么最好的方法是什么?
你认为谷歌真的会受到惩罚吗
重复?
答案 0 :(得分: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
这将永久重定向并调用映射页面,而不会在同一页面上显示尾部'/',并带有尾随'/'