Copied to clipboard

Flag this post as spam?

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


  • Christiaan van Bergen 5 posts 25 karma points
    Jul 24, 2010 @ 14:25
    Christiaan van Bergen
    0

    How do I apply a top level rule for UrlRewriting

    Hi there, I am trying to create a url rewrite rule for the following situation:

    incoming :  http://[domainname]/[personname]
    rewritten :  http://[domainname]/members/[personname].aspx

    I have tried several regular expressions in the UrlRewriting.config but I cannot seem to catch a [personname] (without the suffix .aspx ) to rewrite it. The following I can handle

    incoming: http://[domainname]/A/[personname].aspx
    rewritten : http://[domainname]/members/[personname].aspx

    So it seems to me that the UrlRewriting only applies to one level deeper than the domainname. Is this because: 

    - Umbraco catches it first with some other rule?
    - I have to tell IIS something so it can handle a request that does not have a suffix like .aspx?
    - I have to write my own Rewriting provider as described in the manual of UrlRewriting.net?
    - I am missing a vital piece of the puzzle?

    I do hope that any of you can give me a push in the right direction.

    Thanks. Cheers.

  • Christiaan van Bergen 5 posts 25 karma points
    Jul 24, 2010 @ 17:16
    Christiaan van Bergen
    0

    Hi all,

    I have seemed to fix this in IIS7 by using the URL Rewrite Module. This seemed a way to rewrite it  before Umbraco does.

    The following regular expression I used to get this going: ^([0-9a-z_-]+)$
    After that I rewrote to : members/{R:1}.aspx    et voila!

    If any of you still have an answer for my question for other platforms....please I would like to know if this could be accomplished without having to have access to IIS.

    Cheers!!

  • Sascha Wolter 615 posts 1101 karma points
    Jul 24, 2010 @ 23:50
    Sascha Wolter
    0

    Hi Christiaan,

    I have added the following rewriting rule to my urlrewriting.config file:

        <add name="memberrewrite"
          virtualUrl="^~/(.*)"
          rewriteUrlParameter="ExcludeFromClientQueryString"
          destinationUrl="~/member/$1.aspx"
          ignoreCase="true" />

    That seems to do the trick for me, it redirects everything behind the hostname to /member with an .aspx at the end. However what you are doing here seems to be a bit more complicated then it has to be (from my point of view, obviously I don't know the rest of the story :). Why do the 'virtual' members have to sit directly under the root level, why not point to /member/[membername] in the first place? Is there a good reason for using .aspx? I really wouldn't mix and match them, so either use the directory style urls or .aspx pages. The biggest issue though with this solution is for me that your redirection starts directly at the root of the application, which basically means that either you have to write a nasty RegEx expression to get only the members when redirecting or you are actually handling all the redirection on a second level which seems unnecessary.

    Hope that makes sense,

    Sascha

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jul 26, 2010 @ 10:27
    Tim
    0

    You'll cause yourself no end of problems, becuase the rewrite will rewrite everything on the root of the website, so for example, [domain]/contact.aspx would also go to the members page, so you couldn't have any top level content at all.......

    To make your life easier, stick them in a folder, so the rule can only apply to the things you want, and you won't end up rewriting things that are nothing to do with members.......

    If you absolutely have to have it on the top level, I'd look at writing a custom 404 handler to do it, that way your non-member pages would still work. Check the wiki for details on how to do that!

    :)

  • Christiaan van Bergen 5 posts 25 karma points
    Jul 26, 2010 @ 11:12
    Christiaan van Bergen
    0

    Thanks for the reply guys.

    @Sacha, the rule you wrote will indeed capture everything like Tim said, because of the wildcard used (.*)  . The thing is when I use a more specific capturinggroup like ([0-9a-z_-]+) it will not capture anything at all. According to the documentation of UrlRewriting.net this has to do with IIS not being able to handle url's without extensions. Luckily for me this is all circumvented by using the URL Rewrite Module of IIS7 .

    @Tim, thanks for the hint by using a 404 handler. So what you are saying is: try to handle the page with a rewrite or redirect if it is not normally handled by Umbraco or any of the other rules. Hmmm, I'll give it a try, but is sounds somewhat smelly to me though.

Please Sign in or register to post replies

Write your reply to:

Draft