如何在 htaccess 重写规则中添加分页

how to add pagination in htaccess rewrite rule

我希望使用 htaccess 添加分页。

可见URL:

example.com/test/page2

收件人:

example.com/test/pagination.php?page=2

提前致谢。

基本上你只需要捕获页码,然后将其回收到正确格式的URL。

RewriteRule ^test/(\d+)/*$ /test/pagination.php?page= [L]
RewriteRule                                                  : Type of action
            ^test/(\d+)/*$                                   : Regex to run against URL
                           /test/pagination.php?page=      : Replacement URL
                                                        [L]  : Flags; L == Last

示例:

example.com/test/5     >>>     example.com/pagination?page=5