首页 > 解决方案 > 如何在 htaccess 重写规则中添加分页

问题描述

我正在寻找添加分页htaccess

可见网址:

example.com/test/page2

到:

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

提前致谢。

标签: php.htaccesspagination

解决方案


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

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

例子:

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

推荐阅读