views:

86

answers:

1

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?

+1  A: 

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.

gahooa
Sorry if I made it confusing, I have all the regex and mod-rewrite working, my problem is my php function that generates paging links when needed, i am having a hard time trying to have it make the new links correctly, instead of using the page=12 which almost works, if I am on the first page where the paging number is not in the URL yet....
jasondavis
but once I go to a page, then it would create domain.com/mail/page2/page3
jasondavis
@jasondavis: I think you misunderstand the mod-rewrite: mod-rewrite should transform the pretty urls that people click on back to uls your app can read without visitors seeing the ugly url. So apart from optionally modifying the regex, the last line says it all: *So aside from **generating** new URL's, your application need not change at all.*
jeroen
@jeroen I do understand that, my issue is the <b>genrating</b> new URL's, that is what I am trying to do is gererate the proper url's in my paging code, my paging code currently uses the GET variables to reconstruct the URL and add in the proper page numbers, I cannot do that with my current code, trust me it is not a drop in solution, my mod-rewrite works perfect sitewide and I understand it, I need help generating the proper paging URL's in my PHP code not the regex
jasondavis
you can view my question here to see some of the paging code http://stackoverflow.com/questions/1469067/need-help-with-my-pager-php-function-now-that-i-use-mod-rewrite
jasondavis
jeroen
the problem is instead of just adding /page-".$pagenumber to the link, my paging code reads the URL it is on so it would make it /page-".$pagenumber/page-".$pagenumber 2 times basicly and other stuff, I made a new question in which I describe in great detail the problem and provide the full source code, I am going to add a bounty to that question when SO allows me to, I think it takes some time before I can do it
jasondavis
I will pick your answer for the sake of closing this question
jasondavis