+ Reply to Thread
Results 1 to 5 of 5
Like Tree3Likes
  • 1 Post By hardsteal20
  • 1 Post By misson
  • 1 Post By misson

Thread: Pagination problem with mod_rewrite

  1. #1
    hardsteal20's Avatar
    hardsteal20 is offline x10Hosting Member hardsteal20 is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    6

    Question Pagination problem with mod_rewrite

    In my site I have forum and I use mod_rewrite for getting theme name in URL.

    I used this in .htaccess

    RewriteRule ^forum\:topic\=([0-9]+)-(.*)[^\/]$ forum.php?thread=$1&title=$2 [NC,L]

    But I want to add '&p=1' at the end of url for pagination. But not working.

    Right now my URL is like this:

    mysite.com/forum:topic=1-Topic-Title-Here [It's working]

    But I want:

    mysite.com/forum:topic=1-Topic-Title-Here&p=2 [It's not working]

    Itried the flag QSA too, but fail. I am bad at regular expressions! Any Idea?
    avira.nguyen likes this.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Pagination problem with mod_rewrite

    Note that in your example URL (mysite.com/forum:topic=1-Topic-Title-Here&p=2), the "p=2" is in the path, not the query string, because there is no question mark preceding it. Is that intentional?

    The simplest approach would be to (properly?) place the "p" parameter in the query string, rather the path portion, thusly: mysite.com/forum:topic=1-Topic-Title-Here?p=2

    Rather than brewing your own scheme (the "forum:topic=" format), use the standard URL hierarchical structure. Keep it RESTful.

    Code:
    RewriteRule ^/?forum/thread/([0-9]+)-(.*[^/])$ forum.php?thread=$1&title=$2 [NC,L,QSA]
    URLs would then look like "mysite.com/forum/thread/1-Topic-Title-Here?p=2", though having both the thread number and title in the URL seems redundant.
    Last edited by misson; 07-17-2011 at 05:49 PM.
    avira.nguyen likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    hardsteal20's Avatar
    hardsteal20 is offline x10Hosting Member hardsteal20 is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    6

    Re: Pagination problem with mod_rewrite

    Thanx for your reply, But I don't wanna change the URL structure now [I may need to change internal links too. ] But would try "?".

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Pagination problem with mod_rewrite

    The more you put it off, the more work you'll have to do. You can support both URL formats, using an external redirect from the old to the new.

    Code:
    RewriteRule ^/?forum:topic=([0-9]+-.*) /forum/thread/$1 [R=301]
    As long as any links using the old format exist, on your site or others, you'll need to keep this rewrite.

    In any case, the thread links shouldn't be hardcoded.

    I just noticed you aren't capturing the last non-slash character (the "[^\/]" is outside the parentheses), which probably isn't what you want as it will cut the last character from the title.
    Last edited by misson; 07-17-2011 at 05:51 PM.
    hardsteal20 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    hardsteal20's Avatar
    hardsteal20 is offline x10Hosting Member hardsteal20 is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    6

    Post Re: Pagination problem with mod_rewrite

    Actually, you are right! I wrote this [^\/] because I want that my link should not end up with a '/' . But as you said it's cropping the last character in the URL.

    And THANX a lot for helping me out!

+ Reply to Thread

Similar Threads

  1. problem with mod_rewrite
    By tikki in forum Free Hosting
    Replies: 2
    Last Post: 03-21-2011, 09:40 AM
  2. php pagination problem
    By mlowe.space12 in forum Programming Help
    Replies: 1
    Last Post: 10-15-2010, 03:44 PM
  3. PHP Pagination
    By diabolo in forum Programming Help
    Replies: 6
    Last Post: 06-17-2010, 10:55 AM
  4. PHP Pagination, can someone help please?
    By chibib0 in forum Programming Help
    Replies: 2
    Last Post: 05-03-2008, 09:29 AM
  5. Apache + mod_rewrite problem
    By t2t2t in forum Free Hosting
    Replies: 3
    Last Post: 06-27-2007, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers