【问题标题】:how to add pagination in htaccess rewrite rule如何在 htaccess 重写规则中添加分页
【发布时间】:2021-08-28 17:29:50
【问题描述】:

我希望使用htaccess 添加分页。

可见网址:

example.com/test/page2

收件人:

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

提前致谢。

【问题讨论】:

  • 这能回答你的问题吗? Preety url with htaccess
  • 好的,你试过什么?在网上的数千个示例中,您发现哪些看起来与您想要的相似?提示:Apache 不关心数字是页面而不是 ID,您会发现更多示例。
  • @Steven 您的编辑似乎是对问题的解释,这很可能是想要的,但实际上并不是他们所说的。最好先在评论中要求澄清。
  • 我建议您改用front controller pattern 和众多routers 之一。然后你在你的代码而不是你的 htaccess 文件中定义你的路由。这使得流程更易于阅读/遵循并且更易于设置,而且由于您不需要配置大量供应商特定的重写规则,因此在 Web 服务器之间移动代码会更容易。

标签: php .htaccess pagination


【解决方案1】:

基本上你只需要捕获页码,然后将其回收到格式正确的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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    相关资源
    最近更新 更多