1

我正在使用 IIS7 和 urlMappings 将一些 url 映射到实际页面。

例子:

    <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

我可以添加一个没有尾随“/”的额外条目,以便两者都映射到同一页面,但我不想为 SEO 这样做(认为它是重复的内容)。

是否可以让 urlMappings 重定向?

例如,像这样:

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

如果不是,那么最好的方法是什么?

你认为谷歌真的会惩罚吗

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

http://www.mysite.com/news

作为重复?

4

1 回答 1

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

This will permanently redirect and calls to the mapped page without a trailing '/' to the same page with a trailing '/'

于 2012-02-14T09:38:05.330 回答