Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mladen Macanovic 22 posts 45 karma points
    Nov 09, 2010 @ 11:35
    Mladen Macanovic
    0

    redirect html to aspx

    Hi,

    I managed to convert my company old site from simple html pages to aspx using ubraco. The problem is that the site is indexed on google so if the user try to open the page it will not work because it's an old site that uses html pages. What I need to do is to rewrite all links from .html to .aspx, so I tried to use urlrewriter. Here is the example of the code in UrlRewriting.config:

    <add name="en_sub" 
                virtualUrl="^~/mysitename/en/(.*).html"
                rewriteUrlParameter="ExcludeFromClientQueryString"
                destinationUrl="~/mysitename/en/$1.aspx"
                ignoreCase="true"
                redirectMode="Permanent"/>

    If I try to access .html page it trows me an 404 error. If anyone knows how to do this please help.

  • Seth Niemuth 275 posts 397 karma points
    Nov 09, 2010 @ 12:15
    Seth Niemuth
    0

    I am guessing it does this because .NET is not set up to accept .html pages in your IIS. You will have to set your mappings in IIS to send .html pages to .NET. Are you getting generic 404 error or the umbraco 404 error because if you are getting the generic 404 error page and not the umbraco 404 error page then it is not going through .NET and thus would not go through your URL rewriting rules.

  • Mladen Macanovic 22 posts 45 karma points
    Nov 09, 2010 @ 12:33
    Mladen Macanovic
    3

    I managed to get this work. As you said the IIS was not setup to use html files.

    Here is the solution if anyone needs it.

    First thing that need to be done is to add the html extension in IIS mappings. This is explained in this document UrlRewriting Doc on page 12.

    Second thing is to add appropriate code in the UrlRewriting.config. Here is the example for some of them.

    <add name="en_index"
                   redirect="Domain"
                   ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
                   virtualUrl="http://mysitename/en/(.*).html"
                   redirectMode="Permanent"
                   destinationUrl="http://mysitename/en/$1.aspx" />

    That's it. Hope it help someone.

  • Amir Khan 1287 posts 2744 karma points
    Jan 07, 2011 @ 17:03
    Amir Khan
    0

    Solid, thanks for this!

  • Amir Khan 1287 posts 2744 karma points
    Feb 03, 2011 @ 18:12
    Amir Khan
    0

    To add to this, here's 4 awesome rewriting rules that have been helpful to me:

     

    Canonical Url (example.com to www.example.com)

    <add name="domainRewrite"
    virtualUrl="http://example.com/(.*)"
    rewriteUrlParameter="ExcludeFromClientQueryString"
    destinationUrl="http://www.example.com/$1"
    redirect="Domain"
    redirectMode="Permanent"
    ignoreCase="true" />

     

    Previous pages to their current counterpart (/about-us.html to /about-us.aspx or /about-us, depending on if you use directoryUrls)

    <add name="aboutUsPage"
    redirect="Domain"
    ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
    virtualUrl="/about-us.html"
    redirectMode="Permanent"
    destinationUrl="/about-us" />

     

    Catch all pages with previous file extension incase you miss one, or don't care to manually redirect each page (all non-existing .html to .aspx or extensionless urls):

    <add name="catchAll"
    redirect="Domain"
    ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
    virtualUrl="/(.*).html"
    redirectMode="Permanent"
    destinationUrl="/" />

     

    Umbraco directoryUrls, by default if you enable, a page exists at somepage.aspx and somepage, this 301 redirects the .aspx page to the extensionless url without screwing up the umbraco backend

    <add name="301RedirectDirUrls"
    redirectMode="Permanent"
    redirect="Application"
    ignoreCase="true"
    rewriteUrlParameter="IncludeQueryStringForRewrite"
    virtualUrl="^\/(?!(umbraco\/|data\/|install\/|usercontrols\/|umbraco_client\/))(.*)\.aspx"
    destinationUrl="$1/$2" />

     

    Hope this helps someone!

    Amir

Please Sign in or register to post replies

Write your reply to:

Draft