We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37054
    • 93 Posts
    Can you confirm you have the plugin enabled and set to fire on the WebPageInit event?
      • 36509
      • 127 Posts
      Plugin Disabled box is unchecked
      WebPageInit box is checked

      Confirmed
        www.JBMWebDesign.com
        www.JBMAutomation.com
        • 36509
        • 127 Posts
        Here is what the
        core/cache/includes/elements/modplugin/9.include.cache.php
        looks like.

        <?php
        function elements_modplugin_9($scriptProperties= array()) {
        global $modx;
        if (is_array($scriptProperties)) {
        extract($scriptProperties, EXTR_SKIP);
        }
        //check we are acting on the right system event - in this case onWebPageInit
        switch($modx->event->name){
        case 'onWebPageInit':
        //check if we have the PHPSESSID parameter in our querystring
        if (isset($_GET['PHPSESSID'])) {
        //if so, strip it out
        $requesturi = preg_replace('/&PHPSESSID=[^&]+/',"",$_SERVER['REQUEST_URI']);
        $requesturi = preg_replace('/PHPSESSID=[^&]+/',"",$requesturi); 
        $requesturi = preg_replace('/(\?)$/',"",$requesturi);
         //give Google a 301 response so it knows this redirect to our clean url is permanent
        header("HTTP/1.1 301 Moved Permanently");
        //redirect to our clean URL
         header("Location: http://".$_SERVER['HTTP_HOST'].$requesturi);
         exit;
        }
        break;
        }
        }
        
          www.JBMWebDesign.com
          www.JBMAutomation.com
          • 37054
          • 93 Posts
          Your problem possibly is that you have onWebPageInit rather than OnWebPageInit so the plugin is not getting fired. Also, looking at the regex that strips out the PHPSESSID last night I came up with a more elegant one.

          switch($modx->event->name){
          case 'OnWebPageInit':
          //check if we have the PHPSESSID parameter in our querystring
          if (isset($_GET['PHPSESSID'])) {
          //if so, strip it out
          $requesturi = preg_replace('/(&|\?)PHPSESSID=[^&]+/',"",$_SERVER['REQUEST_URI']);
           //give Google a 301 response so it knows this redirect to our clean url is permanent
          header("HTTP/1.1 301 Moved Permanently");
          //redirect to our clean URL
           header("Location: "http://".$_SERVER['HTTP_HOST'].$requesturi);
           exit;
          }
          break;
          }
          
          [ed. note: freelancewebdev last edited this post 14 years, 6 months ago.]
            • 36509
            • 127 Posts
            Swapped out the code for you just posted and get an error:

            Parse error: syntax error, unexpected T_STRING in /home1/jbmaudio/public_html/core/cache/includes/elements/modplugin/9.include.cache.php on line 17


            It seems the error is in this line:

             header("Location: <a href="<a href="http://".$_SERVER['HTTP_HOST'].$requesturi"" target="_blank" rel="nofollow">http://".$_SERVER['HTTP_HOST'].$requesturi"</a>
              www.JBMWebDesign.com
              www.JBMAutomation.com
              • 36509
              • 127 Posts
              Ok, I took the code from your blog and it is seems to be working now that you made the changes.

              <?php
              //check we are acting on the right system event - in this case onWebPageInit
              switch($modx->event->name){
              case 'OnWebPageInit':
              //check if we have the PHPSESSID parameter in our querystring
              if (isset($_GET['PHPSESSID'])) {
              //if so, strip it out
              $requesturi = preg_replace('/(&|\?)PHPSESSID=[^&]+/','',$_SERVER['REQUEST_URI']);
              $requesturi = preg_replace('/(\?)$/',"",$requesturi);
               //give Google a 301 response so it knows this redirect to our clean url is permanent
              header("HTTP/1.1 301 Moved Permanently");
              //redirect to our clean URL
               header("Location: http://".$_SERVER['HTTP_HOST'].$requesturi);
               exit;
              }
              break;
              }


              But the code you just posted, i get errors with.
                www.JBMWebDesign.com
                www.JBMAutomation.com
                • 37054
                • 93 Posts
                The parser here is injecting a link into the code because it sees a 'http://' in it - that is what is breaking the code - have updated the blog post to reflect the final code.
                  • 36509
                  • 127 Posts
                  Everything seems to be working now.....thanks!
                    www.JBMWebDesign.com
                    www.JBMAutomation.com
                    • 36509
                    • 127 Posts
                    My next question is this. My host won't let me add these lines to the .htaccess file.

                    php_flag session.use_trans_sid off
                    php_flag session.use_only_cookies on
                    


                    it says i need to use the php.ini file

                    is there a way around this?
                      www.JBMWebDesign.com
                      www.JBMAutomation.com