Pagination and .htaccess

2019-08-29 03:59发布

问题:

I am currently showing results using the following url index.php?id=1 and using .htaccess to rewrite it like cat/sub-cat/ and i am using pagination and the url to the next page is index.php?page=2 etc but i can't seem to get the pagination to work with my .htaccess rewritten url so for example threads/thread-name/ shows the page fine etc but when i click on the next page link i just get the same page, if i use the normal url such as index.php?id=1&page=2 that works fine but i can't seem to get it to work in a nicer fashion

Hope that explains the issue clearly :)

回答1:

If I understand your problem correctly, then you need a rewriterule something like this:

RewriteRule ([a-zA-Z_-]+)/([0-9]?) index.php?id=$1&page=$2

Which then directs /mycoolpage/2 to index.php?id=mycoolpage&page=2 etc

And if the last number is not present, then the page query parameter will simply be blank (so you'd assume page=1)