We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    This is an auto-generated topic for <a href="http://modxcms.com/extras/package/572">Tiny Url 0.2-rc1</a> by creotiv.

    Brief Description:
    Makes tiny url based on article id For example: http://site.com/folder1/folder2/article can be achieved by url http://site:com/35
      • 8883
      • 59 Posts
      Thanks for sharing.
      I added a 301-header because of SEO.

      my version:
      $e = $modx->Event;
      
      switch($e->name) {
        case 'OnPageNotFound':
          if(preg_match('@^\/([0-9]+)$@',$_SERVER['REQUEST_URI'])) {
                $uri=preg_replace('@[^0-9]@','',$_SERVER['REQUEST_URI']);
                $cont=$modx->getDocument($uri);
                if($uri && count($cont)>5) {
                      $Url= $modx->makeUrl($uri);
                      header("HTTP/1.1 301 Moved Permanently"); 
                      header($modx->sendRedirect($Url));
                }
          }
        break;
        default:
        break;
      }