Search code examples
asp.netiis-7url-mapping

IIS urlMappings redirects and SEO


I am using IIS7 and urlMappings to map some urls to actual pages.

Example:

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

This works great if the url has a trailing '/' , example:

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

But I get page not found error if I do this:

http://www.mysite.com/news

I could add an extra entry without the trailing '/' so that both map to the same page, but I don't want to do this for SEO (would think it is duplicate content).

Is it possible to get the urlMappings to redirect?

For example, something like this:

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

If not, what would be the best way of doing this?

Do you think google would really penalize

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

http://www.mysite.com/news

as duplicate?


Solution

  • Here is my work around:

    I add both entries, with and without trailing '/', to the urlMappings in web.config

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

    Then in the page itself add the following code on 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 '/'