We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43134
    • 11 Posts
    If you want friendly URL for GetPage example:
    mysite.ru/category/?page=2 
    mysite.ru/category/subpage/?page=2 
    mysite.ru/category/subpage/subsubpage/?page=2 
    

    to
    mysite.ru/category/page-2/ 
    mysite.ru/category/subpage/page-2/ 
    mysite.ru/category/subpage/subsubpage/page-2/ 
    

    It is necessary to make:

    • Сreate Snippet And to include an event "OnWebPagePrerender"
    • Add this code:
    event->name === 'OnWebPagePrerender') {
        $output = $modx->resource->_output;
        $output = preg_replace('%(.+?)/\?page=(.+?)%mis', '$1/page-$2/', $output);
        $modx->resource->_output = $output;
    }
    

    This code will change links
    mysite.ru/category/?page=2 

    To
    mysite.ru/category/page-2/ 


    • Create web rules for nginx
    • Add this code:
    rewrite ^/(.+?)/page-(.*)$ /$1/?page=$2 last;
    location / {
        try_files $uri $uri/ @modx-rewrite;
    }
    

    Everything is ready
    • Thanks for sharing smiley

      I think this:

      event->name === 'OnWebPagePrerender') {
          $output = $modx->resource->_output;
          $output = preg_replace('%(.+?)/\?page=(.+?)%mis', '$1/page-$2/', $output);
          $modx->resource->_output = $output;
      }


      Should be:
      if ($modx->event->name === 'OnWebPagePrerender') {
          $output = $modx->resource->_output;
          $output = preg_replace('%(.+?)/\?page=(.+?)%mis', '$1/page-$2/', $output);
          $modx->resource->_output = $output;
      }


      And you mean a plugin, not a snippet.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 38290
        • 712 Posts
        Just curious what _output returns just the URL or is that all the content for that resource? Guess I should start using === vs == for events in plugins
          jpdevries
          • 38290
          • 712 Posts
          Just looked up _output. What's to stop this from say, modifying external links to other sites?
            jpdevries