Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    May 04, 2011 @ 12:13
    Kasper Dyrvig
    0

    Make querystring look like url path

    Hi,

    This may a crazy question, but here it is... How can I make the query string appears as a part of the url path?

    Let me show... I would like this:

    http://www.example.com/productlist?category=abes

    look like this:

    http://www.example.com/productlist/abes

    or:

    http://www.example.com/productlist-abes

    ...without any redirects or anything like that.

    I have found this http://stackoverflow.com/questions/4630720/converting-wordpress-url-path-into-query-string that also describes it. But here I need to work with Umbraco/C#.

    Any ideas?

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    May 04, 2011 @ 12:19
    Hendy Racher
    0

    Hi Kasper,

    Why not use url rewriting rules ?

    There's a commented-out rule in the default /config/UrlRewriting.config file that details almost exacly what you want to do:

    The sample below rewrites a url from 
     "/product/someproductid.aspx" to 
     "/product.aspx?productid=someproductid" 
                 
    The user will not see the rewritten path! The page that will be 
    loaded from umbraco will instead be: "/product.aspx?productid=someproductid" 
                                         
    <add name="produktidrewrite" 
     virtualUrl="^~/product/(.*).aspx" 
     rewriteUrlParameter="ExcludeFromClientQueryString" 
     destinationUrl="~/product.aspx?productid=$1" 
     ignoreCase="true" />

    HTH,

    Hendy

  • Kasper Dyrvig 246 posts 379 karma points
    May 04, 2011 @ 14:52
    Kasper Dyrvig
    0

    It's a nice feature, but I would like something that does the opposite...

    From /product.aspx?id=someproductid to /product/someproductid.aspx

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    May 04, 2011 @ 15:04
    Hendy Racher
    0

    Hi Kasper,

    I'm not sure I understand your requirements, which URL do you want visible in the address bar ?

    Cheers,

    Hendy

     

  • Kasper Dyrvig 246 posts 379 karma points
    May 04, 2011 @ 15:30
    Kasper Dyrvig
    0

    The URL would under normal surcomstanses be /product.aspx?id=someproductid
    I would like it to "do the same thing" but the url representet to the user is /product/someproductid

  • Daniel Bardi 924 posts 2556 karma points
    May 06, 2011 @ 19:24
    Daniel Bardi
    0

    Hendy's solution is correct.

    @Kaster: use the above solution.. it will work for what you want.

    In your site when directing the user..use something like /product/1234.aspx and urlrewriting will take care of direct the server to /product.aspx?productid=1234

    Users will always see /product/1234.aspx

    You will be able to access querystrings in your code as Request.QueryString["id"]

    Your confusion is not uncommon... urlrewriting does not rewrite to the client, but rewrites to the server.

    Can anyone validate me on this?

  • Kasper Dyrvig 246 posts 379 karma points
    May 09, 2011 @ 13:43
    Kasper Dyrvig
    0

    Hi Daniel

    Your explanation make sense to me. :o)

    Now I just have to try it. I'll let you know how it turns out.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies