We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46463
    • 8 Posts
    I have a javascript app with MODX as the "site shell" wrapped around it. It is a beautiful thing. FURLs are enabled and they are working well.

    So let's say I have "cars" setup as a resource (with "cars" as the alias).

    If I go to www.mydomain.com/cars, my JS app renders a listing of ALL cars in a grid.

    If I go to www.mydomain.com/cars?make=acura, that also works - my app grabs the parameter and renders a filtered list of all Acuras.

    Now, what I am trying to achieve is, a visitor goes to www.mydomain.com/acura, and she would be taken to that same filtered Acuras page.

    I have tried two approaches, neither working.

    Approach 1 - $modx->sendForward:

    As Jason Coward / opengeek has advocated on several occasions (http://forums.modx.com/thread/2833/customized-url#dis-post-17596 and http://forums.modx.com/thread/35476/can-snippets-plugins-make-use-of-intercept-friendly-urls#dis-post-194484 for instance), this is a good way to map dynamic friendly URLs tied to a single resource, by binding a plugin to the OnPageNotFound event. And it does work - but it seems only MODX can see the parameter that is passed - my non-MODX app is not seeing it.

    <?php
    //simple hard-coded test just to prove the concept.  "cars" Resource ID = 11
    //the parameter gets passed such that MODX can see it at the destination resource, but my JS/PHP app is not seeing it
    
    $_GET['make'] = acura;
    $modx->sendForward(11);
    ?>
    


    Approach 2 - htaccess:

    I saw http://forums.modx.com/index.php?topic=60038.0, and can't get that working either.

    I feel the following should work, but there is some conflict with how MODX does FURLs?

    #again, simple hard-coded test to prove the concept
    #the following actually does get to the cars page successfully, but does not pass the make parameter!
    
    RewriteRule ^acura$ cars?make=acura [L,QSA]
    
    # The Friendly URLs part (MODX standard)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    


    Totally stumped. Would love to hear from Jason or others with input on how to solve this.

    Thanks

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      I think if you take the L out of the first RewriteRule, the .htaccess approach might work.

      You might also be able to set a $_SESSION variable in your code and read it on the target page.

      $_SESSION['make'] = 'acura';



      if (isset($_SESSION['make') && (!empty($_SESSION['make'])) {
         $_GET['make'] = $_SESSION['make');
      }
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 46463
        • 8 Posts
        Thank you BobRay...between the RewriteRule change and a change in my JS code, I'm able to get it working
          • 3749
          • 24,544 Posts
          I'm glad you got it sorted. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting