We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4626
    • 57 Posts
    Hi again, did you want it to convert from document?page=x to document-2? I thought you wanted it to internally handle pages with the ur document-2 as index.php?1=document&page=2.
      • 24278
      • 165 Posts
      @carl -- you are right. i want to convert from ...document?page=x to ...document-x . Is this possible?

      @susan -- thank you for the link. Will refer read that too.
        • 4626
        • 57 Posts
        Hi again,

        I don’t really understand why you would want to go from document?page=x to document-x. If you generate the links you could use the -x syntax directly....

        I’m not sure if it is possible to go the other way in mod_rewrite. The only way I know is by doing it in php in the inde.php-page...
          • 24278
          • 165 Posts
          Hi,

          I dont know if I have been able to explain my self clearly... maybe you understood and have given me some suggestion for it, but I am not getting the idea clearly. I will try again... smiley

          using modx 0.9.5 and have alias and path turned on
          I have a URL which looks like this
          http://www.domain.com/folder/document-name

          I use a snippet which splits the document content into multiple pages; and; the current page number is provided as ...?page=1 or ...?page=2
          http://www.domain.tld/folder/document-name?page=1 (shows the first part of the content)
          http://www.domain.tld/folder/document-name?page=2 (shows the second part of the content)
          ...

          I would like the URL to look like
          http://www.domain.tld/folder/document-1 (for first page)
          http://www.domain.tld/folder/document-2 (for second page)
          ...

          I hope this is possible. I appreciate all the time and effort. I’m still learning... smiley
            • 4626
            • 57 Posts
            What snippet are you using to paginate and how do you output the links?
              • 24278
              • 165 Posts
              The pip plugin was converted to a snippet as under...

              <?php
              /*
               *	Name: Pip (Pagination Plugin)
               *	Version: 1.0
               *	Author: Armand "bS" Pondman ([email protected])
               *	Updated: June 7, 2006 12:00 CET
               *
               *  Description:
               *  will paginate a document when delimiter is found in the content. 
               */
              
              ## CUSTOMIZE ##
              
              $delimiter = '<!--pb-->';
              $tplLinkNext = '<a href="[+link+]" title="Next page">»</a>';
              $tplLinkPrev = '<a href="[+link+]" title="Previous page">«</a>';
              $pages = '';
              $tplLinkNav = 'Page [+linkprev+] [+pages+] [+linknext+]';
              $tplInform = '-- Page [+current+] of [+total+]';
              
              $pipPages = '';
                  $pip_content = $modx->documentObject['content'];
              	$pip_pagecontent = explode($delimiter,$pip_content);
              	$pip_pagecount = count($pip_pagecontent);
              	
              	if ($pip_pagecount > 1)
              	{
              	  $pip_currentpage = isset($_GET["page"]) ? floor(abs($_GET["page"])) : 1;
              	  if ($pip_currentpage > $pip_pagecount || $pip_currentpage < 1) { $pip_currentpage = 1; }
              	
              	  $char = ($modx->config['friendly_urls'] == 0) ? "&" : "?";
              	  $url = $modx->makeurl($modx->documentIdentifier,'',$char.'page=');
              	  
              	  $prevpage = $pip_currentpage-1;
              	  $nextpage = $pip_currentpage+1;
              	  
              	  $linkprev = ($prevpage>1 && $prevpage!=1) ? str_replace("[+link+]",$url.$prevpage,$tplLinkPrev) : '';
              	  if ($prevpage==1) {$linkprev = str_replace("[+link+]",$modx->makeurl($modx->documentIdentifier),$tplLinkPrev);}
              	  $linknext = ($nextpage>$pip_pagecount) ? '' : str_replace("[+link+]",$url.$nextpage,$tplLinkNext);
              	  
              	  for ($x=1; $x<=$pip_pagecount; $x++) {
              	  	  if ($x != $pip_currentpage) {
              	  	  	  if ($x == 1)
              	  	  	  	  $pages .= '<a href="'.$modx->makeurl($modx->documentIdentifier).'" title="Page '.$x.' of '. $modx->documentObject['pagetitle'].'">'.$x.'</a> ';
              	  	  	  else
              	  	  	  	  $pages .= '<a href="'.$modx->makeurl($modx->documentIdentifier,'',$char.'page='.$x).'" title="Page '.$x.' of '. $modx->documentObject['pagetitle'].'">'.$x.'</a> ';
              	  	  }
              	  	  else {
              	  	  	  $pages .= '<span class="active">'.$x.'</span> ';
              	  	  }
              	  }
              	  
              	  $tplLinkNav = str_replace("[+linkprev+]",$linkprev,$tplLinkNav);
              	  $tplLinkNav = str_replace("[+linknext+]",$linknext,$tplLinkNav);
              	  $tplLinkNav = str_replace("[+pages+]",$pages,$tplLinkNav);
              	  
              	  $tplInform = str_replace("[+current+]",$pip_currentpage,$tplInform);
              	  $tplInform = str_replace("[+total+]",$pip_pagecount,$tplInform);
              	
              	  $pip_content= $pip_pagecontent[$pip_currentpage-1];
              	  $modx->setPlaceholder('pipPages', $tplLinkNav);
              	  if ($pip_currentpage != 1) // don't show info on first page
              	  	$modx->setPlaceholder('pipInform', $tplInform);
              	}
              	return $pip_content;
              ?>
              
                • 4626
                • 57 Posts
                Try commenting out (row 31?)
                $char = ($modx->config['friendly_urls'] == 0) ? "&" : "?";

                and changing (row 32?) from:
                $url = $modx->makeurl($modx->documentIdentifier,'',$char.'page=');

                to:
                $url = $modx->makeurl($modx->documentIdentifier, '', '-');


                and (row 46?) from:
                $pages .= '<a href="'.$modx->makeurl($modx->documentIdentifier,'',$char.'page='.$x).'" title="Page '.$x.' of '. $modx->documentObject['pagetitle'].'">'.$x.'</a> ';

                to:
                $pages .= '<a href="'.$modx->makeurl($modx->documentIdentifier,'','-'.$x).'" title="Page '.$x.' of '. $modx->documentObject['pagetitle'].'">'.$x.'</a> ';


                I haven’t tested this myself but that should change the links and if you have the last htaccess-version i posted it should handle it correctly...
                  • 24278
                  • 165 Posts
                  Hi,

                  tried the suggestions... now the url looks like...
                  http://www.domain.tld/folder/document-name?-2
                  http://www.domain.tld/folder/document-name?-3

                  I guess the question mark is added by makeURL().
                    • 4626
                    • 57 Posts
                    Yes, makeurl adds a ? before the args....

                    What you could do is try...
                    on line 32(?)
                    $url = $modx->makeurl($modx->documentIdentifier').'-';

                    and on line 46(?)
                    $pages .= '<a href="'.$modx->makeurl($modx->documentIdentifier).'-'.$x.'" title="Page '.$x.' of '. $modx->documentObject['pagetitle'].'">'.$x.'</a> ';


                    But like I said before – I haven’t tried it myself...

                    The problem though with this way of doing it is that it could break other snippets/plugins that send args (at least via $_GET) to a new page...
                      • 24278
                      • 165 Posts
                      Ok. got my URLs looking like
                      http://www.domain.tld/folder/document-name-2
                      http://www.domain.tld/folder/document-name-3

                      and using these directives in the .htaccess
                      ...
                      
                      Options +FollowSymlinks
                      RewriteEngine On
                      
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteRule ^(.*)\.html$ http://apv2/$1 [R=301,L]
                      # the above directive does not render css and images if http://apv2/ is removed... otherwise works as expected
                      
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteRule ^(.*)-([0-9]+)$ index.php?q=$1&pg=$2 [L,QSA]
                      
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      
                      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
                      


                      It works. Thank you carl... your are a superstar laugh