We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37044
    • 68 Posts
    Hi I want to be able to link to a page of my modx 2.2.0 with a query string but in the friendly url format.

    Note I have furls turned on and working.

    So I want to be able to go to - www.mysite.com/page/query_id

    which would be re_written to www.mysite.com?index.php?q=page&query_string=query_id

    If I go to www.mysite.com/page/query_id - it 404's to my error page as it is looking for a page with the alias "page/query_id" which doesn't exist.

    I have tried using htaccess rules to no avail just cant the syntax right.

    But have just installed the modx extra 'Articles' which uses urls like the one below but with out any changes to the htaccess file so must do all the rewriting all programatically from within modx?

    http://www.domain.com/articles/2012/04/15/test-news-story/

    So my question is how is it done?

    Any help appreciated! [ed. note: megasteve4 last edited this post 14 years, 5 months ago.]
      • 37044
      • 68 Posts
      In vague answer to my own question - I have got the htaccess to accept my friendly urls such as above and they do redirect to the correct page with the query string but by the time the page has finished loading the url is no longer friendly and has the full /?var=foo syntax - still haven't worked that out.

      However have just stumbled across the location of a 'Plug in' that seems to manage a lot of the redirect stuff / FURLs for the 'Articles'extra. It is located under 'Plug ins' and is called 'ArchivistFurl' but you will obviously have to install the 'Articles' extra first.

      Here is the code from it:

      if ($modx->event->name != 'OnPageNotFound') return;
      
      $archiveIds = $modx->getOption('archivist.archive_ids',null,'');
      if (empty($archiveIds)) return;
      $archiveIds = explode(',',$archiveIds);
      
      /* handle redirects */
      $search = $_SERVER['REQUEST_URI'];
      $base_url = $modx->getOption('base_url');
      if ($base_url != '/') {
          $search = str_replace($base_url,'',$search);
      }
      $search = trim($search, '/');
      
      /* get resource to redirect to */
      $resourceId = false;
      $prefix = 'arc_';
      foreach ($archiveIds as $archive) {
          $archive = explode(':',$archive);
          $archiveId = $archive[0];
          $alias = array_search($archiveId,$modx->aliasMap);
          if ($alias && strpos($search,$alias) !== false) {
              $search = str_replace($alias,'',$search);
              $resourceId = $archiveId;
              if (isset($archive[1])) $prefix = $archive[1];
          }
      }
      if (!$resourceId) return;
      
      /* figure out archiving */
      $params = explode('/', $search);
      if (count($params) < 1) return;
      
      /* tag handling! */
      if ($params[0] == 'tags') {
          $_GET['tag'] = $params[1];
      } else if ($params[0] == 'user' || $params[0] == 'author') {
          $_GET[$prefix.'author'] = $params[1];
      } else {
          /* set Archivist parameters for date-based archives */
          $_GET[$prefix.'year'] = $params[0];
          if (isset($params[1])) $_GET[$prefix.'month'] = $params[1];
          if (isset($params[2])) $_GET[$prefix.'day'] = $params[2];
      }
      
      /* forward */
      $modx->sendForward($resourceId);
      return;


      I will need to examine it further to see if I can mod some of it to fix my issue.