Copied to clipboard

Flag this post as spam?

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


  • Peter Duncanson 430 posts 1360 karma points c-trib
    Mar 09, 2010 @ 14:16
    Peter Duncanson
    0

    Dynamic Urls with data in them?

    I'm hooking a Umbraco build up to a XML feed of properties and I currently have a "read more" link which points to a page like /indepth.aspx?id=1234 and using umbraco.library:Request("id") to get the id. No problem except its not very user/search engine friendly.

    How can I make "sexy" urls in Umbraco that contain data? Something like:

    /property/indepth/street-name/town/1234

    Any ideas?

  • Fredrik Sewén 39 posts 106 karma points
    Mar 09, 2010 @ 14:29
    Fredrik Sewén
    1

    Hi, 

    You could use the built-in URL-rewriter.

    This is one tutorial: http://www.christophertl.net/1513.aspx

    /Fredrik

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 09, 2010 @ 14:32
    Simon Dingley
    1

    Umbraco ships with a url rewriting module called UrlRewriting.net so you can edit your UrlRewriting.config to your requirements. For documentation see http://urlrewriting.net

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    Mar 09, 2010 @ 14:46
    Lee Kelleher
    0

    Yep, UrlRewriting is the way to go... quick example:

    <add name="sexyUrl" virtualUrl="^~/property/indepth/(.*)/(.*)/([\d]*)" destinationUrl="~/indepth.aspx?id=$1" rewriteUrlParameter="ExcludeFromClientQueryString" ignoreCase="true" />

    Cheers, Lee.

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Mar 09, 2010 @ 15:50
    Peter Duncanson
    0

    Awesome response, thanks guys. Already got it working. Next problem though is how to make the urls SEO friendly similar to NiceUrl but without a node id?

    Built up some simple templates which do some swapping of characters and happy to go that route but wondering if there is anything already out there?

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Mar 09, 2010 @ 16:05
    Peter Duncanson
    0

    Quick example. I want to convert this:

    Flat 4 - Some street or other, Huddersfield

    to

    /flat-4-some-street-or-other/huddersfield/

    I'm using this at the minute which works but leaves double "--" in the url :(

     

    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
    <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />

    <xsl:template name="Helpers.toLowerCase"><xsl:param name="input" select="''" /><xsl:value-of select="translate( $input, $uppercase, $lowercase )" /></xsl:template>

    <xsl:template name="Helpers.toSEOFriendly">
        <xsl:param name="input" select="''" />
        <xsl:variable name="dodgyChars" select="' ,.#_-'" />
        <xsl:variable name="replacementChar" select="'-----'" />
        <xsl:variable name="lowercased"><xsl:call-template name="Helpers.toLowerCase"><xsl:with-param name="input" select="$input" /></xsl:call-template></xsl:variable>
        <xsl:variable name="escaped"><xsl:value-of select="translate( $lowercased, $dodgyChars, $replacementChar )" /></xsl:variable>
        <xsl:value-of select="$escaped" />
    </xsl:template>

    <xsl:template match="/">
      Url: <xsl:call-template name="Helpers.toSEOFriendly"><xsl:with-param name="input" select="num" /></xsl:call-template>
    </xsl:template>

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    Mar 09, 2010 @ 16:17
    Lee Kelleher
    1

    Hi Peter,

    You could write an XSLT extension to use built-in Umbraco methods?

    e.g. To remove/replace unwanted characters, use:

    umbraco.cms.helpers.url.FormatUrl( String )

    This method loops through each of the chars from "requestHandler/urlReplacing" in "umbracoSettings.config".

    But if you want to keep it all in XSLT, then using the "translate()" function should be suffice.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft