Pagination problem with mod_rewrite

hardsteal20

New Member
Messages
6
Reaction score
0
Points
0
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? :rolleyes:
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:

hardsteal20

New Member
Messages
6
Reaction score
0
Points
0
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 "?". 8)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:

hardsteal20

New Member
Messages
6
Reaction score
0
Points
0
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. :confused:

And THANX a lot for helping me out! :rolleyes:
 
Top