phpmod-rewritepagination

How can I get the value in the URL and modify it for paging with mod-rewrite on?


I am trying to get my old paging class to work which relied on the variables available with $_GET in PHP to reconstruct the URL for the paging links, it worked great but now I am changing to have "pretty url's" with mod-rewrite.

So this

domain.com/?p=the-pagename-identifier&userid=12&page=3

would now be

domain.com/the-pagename-identifier/12/page-3

Problem is my PHP for my old paging would rely on the GET variables to re-construct the URL and make sure any variables present in the URL remain in the new URL's it makes for new pages, now I am stuck because I need it to work with the "virtual" directories that it appears I have in the URL, domain.com/mail/inbox/page-12 is really in the root directory running through my index file domain.com/index.php?p=mail.inbox&page=12

I am lost because some pages will have more things then others in the GET part of the URL.

Since all pages are loaded through the index.php at root level I could almost just link the pages without the full URL path but instead of something like domain.com/mail/page-2 it would end up being domain.com/page-2 since the mail directory in the example is not a real directory. So is it possible to get the value in the URL of a page that was made with mod-rewrite so I can make it think it is in a subfolder and just add the page number onto the current URL of a page?


Solution

  • This rewrite rule:

    RewriteRule ^/([0-9a-zA-Z-]+)/([0-9]+)/page-([0-9]+)$  /index.php?p=$1&userid=$2&page=$3
    

    Would transform this:

    domain.com/the-pagename-identifier/12/page-3
    

    Into this:

    domain.com/?p=the-pagename-identifier&userid=12&page=3
    

    Completely transparent to the end user.

    So aside from generating new URL's, your application need not change at all.