We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33510
    • 13 Posts
    I’m having trouble creating a snippet to contain the search results that come from my Google Co-Op custom search engine.

    The problem is that google uses the "?q=Search+Term" varable and it seems that MODx uses the same variable to find pages.

    Is there a way around this? I’m not too keen on modifying the MODx core just to make this work, but I can’t seem to figure out a way to pass this variable into a snippet without totally confusing MODx.

    Has anyone had this same problem? I couldn’t find anything on it in the forums.

    Any input would be appreciated.
      • 33510
      • 13 Posts
      Ok, I found a workaround hack.

      I changed the file document.parser.class.inc.php

      Line 258:
      Original:
              if (isset ($_REQUEST['q'])) {
                  return "alias";
              }
      

      Changed to:
              if (isset ($_REQUEST['alias'])) {
                  return "alias"; // MODIFIED from 'q' to 'alias'
              }
      


      And I changed the .htaccess file:

      Line 45:
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      

      Changed to:
      RewriteRule ^(.*)$ index.php?alias=$1 [L,QSA]
      


      I did this so I could use my Google Custom Search Results Snippet.

      If anyone’s interested in the Snippet, or has any suggestions on something better to do, please let me know.
        • 27376
        • 576 Posts
        If your google snippet uses [tt]?g=Search+Request[/tt] and MODx uses [tt]?q=alias/path[/tt] then why did you have to change it huh

        q is not g...
          • 33510
          • 13 Posts
          Quote from: sirlancelot at May 04, 2007, 04:30 PM

          q is not g...

          Gee, you think? laugh tongue

          Thanks for the heads up... I fixed the post. I hope it makes sense now. Let me know if you are still confused.
            • 27376
            • 576 Posts
            hehe that makes more sense smiley I thought it would be that ’cause google uses the ’q’ for all queries and so does MODx...
              • 7923
              • 4,213 Posts
              You don’t need to hack the core code, use the furls, see: http://wiki.modxcms.com/index.php/Friendly_URLs_Guide#SEO_.28Google.29_Friendly_URLs


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 27376
                • 576 Posts
                doze, when furls are turned on, MODx uses the ’q’ parameter (look at [tt].htaccess[/tt]), and so does zgambino’s snippet (which apparently can’t be changed).
                  • 7923
                  • 4,213 Posts
                  Yes.. but I didn’t mean that he would use .htaccess.. I meant that he would do what I linked to. Doing that, he can change the q to be what ever he wants. Or did I not understand something..?


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 17329
                    • 53 Posts
                    I have the same problem as zgambino.
                    I did what he suggested but I had to change ’q’ to ’alias’ in 4 places in the file ’document.parser.class.inc.php’ to get it working (doing search/replace).

                    @doze
                    I don’t see what in the instructions for friendly URLs would solve the problem we have. The only parameter that come close is ’Prefix for friendly URLs:’ put it doesn’t apply. In my case I use alias and alias path.

                    The use of the parameter ’q’ is hard coded in ’document.parser.class.inc.php’ and does collide with the parameter for the query string in Google Search.

                    lionel
                      • 27376
                      • 576 Posts
                      When furls are on, the entire string (URL) is sent to MODx via the ’q’ parameter regardless of any MODx setting.

                      For instance, if I have: [tt]http://www.example.com/sub/page.html[/tt] furls are on as well as friendly alias path. Apache will rewrite the url to this: [tt]http://www.example.com/index.php?q=sub/page.html[/tt] and MODx would process it.

                      if the alias prefix were ’[tt]index.php?page=[/tt]’ and suffix was blank, with "Use friendly aliases" turned off, and you had a request like this: [tt]http://www.example.com/index.php?page=432[/tt], Apache would rewrite the url to this: [tt]http://www.example.com/index.php?q=index.php?alias=432[/tt] and MODx would process it.

                      Apache doesn’t know MODx’s prefix and suffix.