Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 16, 2012 @ 13:14
    Bo Damgaard Mortensen
    0

    URL Rewrite issue

    Hi all,

    I have some trouble with url rewriting / 301 redirects. The client has got around 1650 rewrites from their old page to their new page. These urls often ends with .html and a lot of other extensions rather than .aspx. I managed to get the UrlRewrite.config file running with all 1650 rules which actually made the redirects. However, the server went to 100% cpu load because of this :-/ I guess it's because of the amount of rules?

    Is there any other way to achieve this? I have tried with global.asax and a 404 handler, but when I enter an URL with an extension that is not .aspx, the iis gives a 404 not found page.

    Anyone got a hint/suggestion on this one?

    Thanks a lot in advance.

    - Bo

  • Stephen 767 posts 2273 karma points c-trib
    Nov 16, 2012 @ 13:17
    Stephen
    0

    Running on which version of IIS? If IIS7 or more, I'd suggest using the build-in rewriting module + static rewrite map.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 16, 2012 @ 13:24
    Bo Damgaard Mortensen
    0

    Hi Stephen,

    Yep, it is IIS7 :-) But isn't the build in rewriting module on the iis the same as when you enter URLs in the UrlRewrite config?

    I have no clue about what a static rewrite map is ;-) Have to read up on that.

    Thanks!

  • andy_rose 91 posts 117 karma points
    Nov 16, 2012 @ 13:25
    andy_rose
    0

    Out of interest do you really need 1650 rules? Is there any kind of pattern to the redirect?

    An alternative is to write a NotFoundHandler implementing the umbraco.interfaces.INotFoundHandler interface method and adding it to the list of NotFoundHandlers specified in the 404handlers.config. We have implemented something like this that references a cached key/value list of redirects and forwards if one is found.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 16, 2012 @ 13:28
    Morten Bock
    0

    Low practical:

    How about making a rewrite that sends *.html to /myhandler.aspx?oldurl=$1, which will then 302 redirect to whatever new location it should go to?

  • Mads Krohn 211 posts 504 karma points c-trib
    Nov 16, 2012 @ 13:33
    Mads Krohn
    0

    No, the IIS Url Rewrite module (http://www.iis.net/downloads/microsoft/url-rewrite) and the build in rewrite stuff in Umbraco are NOT the same.
    The build-in Umbraco rewrite functionallity is built upon http://www.urlrewriting.net and it is known for scaling very poorly.

    I would suggest the something along the lines of what Stephen suggested.

    Either try and use the IIS Url Rewrite module. If thats not an option, I think you should be able to force IIS to serve .html extension through to the .NET pipeline via settings in the web.config. I would probably write a HttpModule and register it in the 404handlers.config.

    Is that enough to start on ? Let me know if you need help setting any of this up.

    Kind regards

    Mads

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 16, 2012 @ 16:46
    Bo Damgaard Mortensen
    0

    Hi all,

    Sorry for the late response here. It's been three hours of pure stress :-)

    I went for the web.config url rewriter with a rewrite map as config source which works like it should.

    The web.config looks like this:

    rewrite>                
            <rewriteMaps configSource="rewritemaps.config"></rewriteMaps>
    
            <rules>
              <rule name="Redirect rule1 for Redirects">
                <match url=".*" />
                <conditions>
                  <add input="{Redirects:{HTTP_HOST}{REQUEST_URI}}" pattern="(.+)" />
                </conditions>
                <action type="Redirect" url="http://{C:1}" appendQueryString="false" redirectType="Permanent"/>
              </rule>          
            </rules>
          </rewrite> 

    This goes in the <system.webServer> snippet.

    My rewritemaps.config then looks like this:

    <rewriteMaps>
      <rewriteMap name="Redirects">
    <add key="www.myoldurl.html" value="www.mynewurl.aspx" />
    <add key="www.myoldurl1.html" value="www.mynewurl1.aspx" />
    </rewriteMap>
    </rewriteMaps> 

    Only downside of this (at least when you haven't got access to the webserver) is that your rewritemaps.config file must not exceed the filesize of 250kb! Which lead to leavinging some (actually a lot) urls out for now.

    This leaves me with the following question. Using the web.config rewriter, is there any way to make a general redirect rule to save some size in the rewritemaps.config? In this particular case I have a *lot* of urls looking like this:

    www.mysite.com/subpage1/subpage2/page1.html
    www.mysite.com/subpage1/subpage2/page2.html 
    www.mysite.com/subpage1/subpage2/page3.html 
    www.mysite.com/subpage1/subpage2/page4.html 
    www.mysite.com/subpage1/subpage2/page5.html 

    The above urls all point to the same page: www.mynewsite.com/mynewpage1.aspx

    Thanks again! All of your help and hints are greatly appreciated :-)

    All the best,

    Bo

  • Stephen 767 posts 2273 karma points c-trib
    Nov 16, 2012 @ 17:22
    Stephen
    0

    Then maybe you can have one non-static rule matching /subpage1/subpage2/(.*) and redirecting to /subpage1/subpage2/mynewpage1.aspx.

Please Sign in or register to post replies

Write your reply to:

Draft