We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi there, I'm using getPage on a blog page with friendly URLs, based on some other threads in this forum. The only problem is that on pages with a number above 9, only the first digit gets through. So when I'm on page 11, modx shows page 1. When I'm on page 23, I get page 2. And so on. The url that is generated is correct though.

    This is the friendly url plugin (onWebPagePreRender):
    $id = $modx->resource->get('id');  
    if ($id == '2')  {  
      $output = $modx->resource->_output;
      $output = preg_replace('%/(.+?)\?page=([0-9]+)%mis', '/$1/page-$2', $output);    
     
      // don't show page-1 on page 1
      $output = preg_replace('%/(.+?)/page-1/%mis','/$1', $output);
      $modx->resource->_output = $output;
    }
    
    


    And this is the htaccess code (placed above 'the friendly urls part'):
    # friendly pagination urls
    RewriteCond %{REQUEST_URI} /(.+?)/page-(.+?) [NC]
    RewriteRule (.*) /%1?page=%2 [L,QSA,NC]
    


    It must be something simple, I just can't get it to work for pages with a number above 9. I hope someone can spot my mistake!
      • 19328
      • 433 Posts
      I found the problem, I think.
      In the .htaccess file, the code needs to be:
      # friendly pagination urls
      RewriteCond %{REQUEST_URI} /(.+)/page-(.+) [NC]
      RewriteRule (.*) /%1?page=%2 [L,QSA,NC]
      


      Apparantly the questionmark in the regular expression made it 'lazy', it only took the first matching character. Without the question mark it works. For anyone struggling with regular expressions, this is a handy tool: http://gskinner.com/RegExr/ (a visual regular expressions editor)