We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18273
    • 3 Posts
    Hi,

    I have recently started my first site http://www.midlandimports.com using the modx framework and am very impressed smiley

    I just have a query regarding friendly urls and my snippet.

    The snippet queries an oscommerce (shopping cart) database and pulls back products into Modx depending on a specific Category ID (Template Variable).

    The Snippet Call is: [!OscGetProducts ?CategoryID=`[*categoryID*]` !]

    At the minute all returned products are passed to products.html in the form

    <a href="/products.html/?product=[+rnProduct+]&id=[+rnID+]>Click Here for Products<a/>

    E.g http://www.midlandimports.com/products.html/?product=Flag&id=29

    For SEO reasons, I would however like the productname to be in the the url e.g Flag/product.html. But I do not want to import a thousand products into the database when I could just query them and use product.html to output them.

    Any ideas on how to make this work?


    Many Thanks

    Marcus
      • 15083
      • 697 Posts
      Hi there,

      What your doing is tricky as MODx is already re-writting urls.
      Rather than put the id 29 can you not put in its matching product name, IE

      http://www.midlandimports.com/products.html/?product=Flag&name=big-english-flag

      In your snippet you could then so a lookup on "big-english-flag" + match it to the ID. Basically it what MODx does with friendly urls enabled.
        • 29774
        • 386 Posts
        You can do this by using a plugin tied to the system event OnPageNotFound event. Have your product listing snippet output the various products links like this:

        /product/flag/

        In the plugin parse the request url, then use $modx->sendForward() to ’forward’ the page (without actually reloading it) to:

        http://www.midlandimports.com/products.html/?&name=flag

        Of course you would need to change your product display snippet to grab the product name from $_GET[’name’] and write an SQL query to retrieve the appropriate product from your db and display it.

        You may also wish to use an friendly url alias field in your product table to reference the product as well as storing it’s name (maybe oscommerce already does this?)
          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
          • 18273
          • 3 Posts
          Thanks for your responses guys.

          I opted for your method in the end therebechips

          Very powerful stuff.

          Cheers

          :)