We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18654
    • 191 Posts
    Quote from: OpenGeek at May 23, 2011, 01:54 PM

    FWIW, I would use this OnPageNotFound to handle your custom routing. That way the MODX routing still works and your custom handling occurs after it fails. Otherwise, you might interfere with the default MODX routing unintentionally.

    Thanks for the input! I’ll make that change.
      God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
      • 18654
      • 191 Posts
      Final code with onPageNotFound hook:

      <?php
      
      /*
       *  Routes
       */
      
      $urlSegments = explode('/', $_SERVER['REQUEST_URI']);
      $urlPath = trim($urlSegments[0] . '/' . $urlSegments[1] . '/' . $urlSegments[2], '/');
      $rewritePatterns = array(
      	'/^blog\/post/' => 1324,
      	'/^blog\/archives/' =>  1321,
      	'/^blog\/category/' => 1322,
      	'/^blog\/tag/' => 1323,
      	'/^news-events\/media-coverage/' => 3,
      	'/^news-events\/media-coverage\/archive/' => 3,
      	'/^news-events\/newsletters/' => 3,
      	'/^news-events\/newsletters/archive/' => 3,
      );
      
      foreach ($rewritePatterns as $pattern => $target) {
      	if (preg_match($pattern, $urlPath)){
      		$modx->sendForward($target);
      	}
      }
      


      Thanks again for the tip OpenGeek - using the onPageNotFound hook is a much better approach than onHandleRequest method.
        God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.