Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Oct 23, 2011 @ 17:24
    Profiterole
    0

    Url rewriting

    Hi,

    I must use urlrewriting in Umbraco because I don't have acces to IIS.

    So, I'm only try to redirect mysite.com/m or www.mysite.com/m to www.mysite.com/someurl.aspx

    My regex skills are near 0, so here's my code that does not work :

    <add name="redirect mobile" 
    redirect="Domain" 
    ignoreCase="true" 
    rewriteUrlParameter="IncludeQueryStringForRewrite" 
    redirectMode="Permanent" 
    virtualUrl="/m" 
    destinationUrl="/a-propos/mobile.aspx" />


  • Jamie Howarth 306 posts 773 karma points c-trib
    Oct 23, 2011 @ 17:44
    Jamie Howarth
    1

    Hi Profiterole,

    Try this:

    <add name="redirectMobile" redirect="Domain"
    ignoreCase="true"
    rewriteUrlParameter="IncludeQueryStringForRewrite"
    redirectMode="Permanent"
    virtualUrl="^~/m$"
    destinationUrl="~/a-propos/mobile.aspx" />

    Three main differences:

    1. The "name" attribute should ideally not contain spaces;
    2. The "virtualUrl" attribute should begin with a caret ^ (to anchor the regex to the start of the URL), followed by tilde ~ (to handle the virtual path of the request), and end with dollar $ (to mark the end of the string);
    3. The "destinationUrl" attribute should begin with a tilde ~ to handle the virtual path of the URL to rewrite to.

    Try this and let us know how you get on.

    HTH,

    Benjamin

  • Profiterole 232 posts 264 karma points
    Oct 23, 2011 @ 19:43
    Profiterole
    0

    Hi Benjamin,

    Thank you for your help. After the changes, I got "mysite.com/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/a-propos/mobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspxobile.aspx"

     

    And got en error. As you can see, it repeats the destination url...

  • Profiterole 232 posts 264 karma points
    Oct 25, 2011 @ 01:57
    Profiterole
    0

    Ok, still not answered. I'm not using extensionless site, so is it possible that the server does not know what to do with /m whitout extension?

  • wolulcmit 357 posts 693 karma points
    Oct 25, 2011 @ 02:44
    wolulcmit
    1

    Hi Profiterole, try taking the redirect="domain" out of the equation and it should work.
    you should be left with something like:

    <add name="RedirectMobile"
             redirectMode="Permanent"
             ignoreCase="true"
             rewriteUrlParameter="IncludeQueryStringForRewrite"
             virtualUrl="^~/m$"
             destinationUrl="~/a-propos/mobile.aspx" />

    I'm certainly no regex guru either, but the above should work.

    - Tim

  • Profiterole 232 posts 264 karma points
    Oct 25, 2011 @ 14:15
    Profiterole
    0

    Hi Tim, I don't know why I should take off the redirect="domain", but it worked! Thank you!

  • wolulcmit 357 posts 693 karma points
    Oct 26, 2011 @ 02:43
    wolulcmit
    0

    Again, from my limited knowledge of the subject (and a quick inspection of the documentation)
    you only need redirect="domain" if you are redirecting to another domain, in which case you'd have to include the full path in the destinationUrl i.e destinationUrl="http://www.newdomain.com/a-propos/mobile.aspx" />
    taking this out means its just doing a normal rewrite rather than a redirect.
    you could also specify redirect="Application" which I suspect would work as well.

    check out the documentation:
    http://www.urlrewriting.net/160/en/documentation/documentation/documentation/documentation/documentation/documentation.html it seems to be reasonably comprehensive and is well worth knowing if you're going to be working with redirects a lot.

    anyway, glad you got it working,

    - Tim

Please Sign in or register to post replies

Write your reply to:

Draft