分页和.htaccess [英] Pagination and .htaccess
问题描述
我目前正在使用以下URL index.php?id = 1显示结果,并使用.htaccess像cat/sub-cat/一样重写它,并且我正在使用分页,下一页的URL为index.php? page = 2等,但我似乎无法使用我的.htaccess重写的URL进行分页,因此例如线程/线程名/显示页面正常等,但是当我单击下一页链接时,我得到的却是相同的页,如果我使用正常的网址,例如index.php?id = 1& page = 2可以正常工作,但我似乎无法使其以更好的方式工作
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 :)
推荐答案
如果我正确理解了您的问题,那么您需要这样的重写器:
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
然后将/mycoolpage/2定向到index.php?id = mycoolpage& page = 2等
Which then directs /mycoolpage/2 to index.php?id=mycoolpage&page=2 etc
如果最后一个数字不存在,那么page
查询参数将只是空白(因此您假设page=1
)
And if the last number is not present, then the page
query parameter will simply be blank (so you'd assume page=1
)
这篇关于分页和.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!