Copied to clipboard

Flag this post as spam?

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


  • Sune Jepsen 25 posts 109 karma points
    Jan 08, 2011 @ 09:28
    Sune Jepsen
    0

    Friendly url on custom data in custom section

    If I want to have friendly/nice url on custom data, how do I do that in my xslt.  Currently you are clicking on a category, which then lists the products, my xslt looks like this without friendly url, here's what ive done it with querystring.:

    <xsl:variable name="categoryID" select="umbraco.library:RequestQueryString(categoryid')"/>

     <xsl:variable name="product" select="MyCustomProductLibrary:ListProductByCategory($categoryID)"></xsl:variable>

          
      <ul>
       <xsl:for-each select="$product/product">
          <li>
             <a>
              <xsl:attribute name="href">
              product.aspx?productid=<xsl:value-of select="productID"/>&amp;
               </xsl:attribute>
               <xsl:value-of select="productName"/>
             </a>&nbsp;
           </li>
         </xsl:for-each>
      </ul>

    So how should my xslt look when I want to build the same with friendly urls and how do I reach the querystring after that?

    Last question is how do I set the rule up in the UrlRewriting.config file for this to work. Do I have to change something on my IIS. Currently Im working local on my windows 7 machine.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 08, 2011 @ 10:27
    Jan Skovgaard
    0

    Hi testumbraco

    Are you sure you want to make a nice url out of this? If I understand your intention correctly you want to skip the querystring paramete and then just show the product.aspx page when the visistor goes to a product page no matter the category?

    I don't think that's a good idea SEO-wise - then it's better to have it rewritten like product.aspx/nameofcategorybasedontheidinquerystring.aspx if you catch my drift?

    Unfortunately I'm not sure how to setup the rules in urlrewriting.net yet - but surely some others in here have and should be able to answer this :-)

    /Jan

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 08, 2011 @ 12:45
    Dirk De Grave
    1

    if you want a friendly url on your custom data/content, you'll end up writing your own, which shouldn't be too difficult (using an xslt extension or "hard" coded in your user control). Could for example build urls based on 

    http://www.domain.com/products/category-name(.aspx)  and http://www.domain.com/products/category-name/product-name(.aspx)

    From there on, use urlRewriting to rewrite to

    http://www.domain.com/products/category.aspx?name=category-name and http://www.domain.com/product.aspx?name=product-name

    in urlRewriting.config

    <add name="categoryRewrite" virtualUrl="^~/products/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/category?category=$1" ignoreCase="true" />
    <add name="categoryRewrite" virtualUrl="^~/products/(.*)/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/product?product=$2" ignoreCase="true" />

    (written without have tested...)

    Also assumes you've setup a /category.aspx and /product.aspx page in your content tree (with associated templates)

    But, one thing to be aware of.. make sure to have unique categories and product names....

    Let us know if you need more info...

    Cheers,

    /Dirk

  • Sune Jepsen 25 posts 109 karma points
    Jan 09, 2011 @ 09:16
    Sune Jepsen
    1

    Thanks for the replies.

    I did following steps:

    Ive created products, product and category pages under content.

    From this tuturial I configure my IIS (Wildcard script mapping in IIS 7 classic pipeline mode), this ensures the flat url without .aspx
    http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

    Combined with this setting in the config file
    <add key="umbracoUseDirectoryUrls" value="true" />

    My productlist xslt macro:

      <xsl:variable
        name="products"
        select="sql:GetDataSet('myConn', 'select p.ProductID, p.ProductName, p.CategoryID, c.CategoryName from Products p INNER JOIN Categories c ON p.CategoryID = c.CategoryID', 'Product')"/>

    <xsl:template match="/">
      <ul>
        <xsl:for-each select="$products//Product">
          <xsl:sort select="ProductName"/>
            <li>
              <a>
                <xsl:attribute name="href">
                  products/<xsl:value-of select="CategoryName "/>/<xsl:value-of select="ProductName"/>
                </xsl:attribute>
                <strong>
                  <xsl:value-of select="ProductName"/>
                </strong>
              </a>
            </li>
         </xsl:for-each>
      </ul>
    </xsl:template> 

    Here Ive have my xslt extensions which grabs my products from a database. The highlighted text is my friendly url.

    Then I added a urlrewrite rule to my config

        <add name="produktidrewrite"
         virtualUrl="^/products/(.*)/(.*)"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/product.aspx?productid=$2&amp;category=$1"
         ignoreCase="true"/>

    My final url looks like

    http://mydomain/products/Seafood/Carnarvon-Tigers (where seafood is the category and carnarvon-tiger is the product)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 09, 2011 @ 11:17
    Dirk De Grave
    0

    Seems ok, just be aware of special chars in your urls, such as é, à,  &, ...., they may corrupt the url...

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft