Py学习  »  NGINX

nginx重写PHP分页规则

Alex Cardo • 6 年前 • 857 次点击  

我当前用于分页的URL如下所示:

http://localhost:8000/index.php?slug=the-category-name&type=category&page=1

我想要的网址应该是:

https://mywebsite.com/category/the-category-name/page/1/

如果我只想看到没有分页的类别,我使用这个重写规则:

location /category/ {
            rewrite ^(.*[^/])$ $1/ permanent;
            rewrite  ^/category/(.*)/$ /index.php?slug=$1&type=category 
            last;
    }

这是我获取URL的方式:

https://mywebsite.com/category/the-category-name/

我需要在这个配置中更改什么(附加到)才能创建分页,比如:

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30743
 
857 次点击  
文章 [ 1 ]  |  最新文章 6 年前
Richard Smith
Reply   •   1 楼
Richard Smith    6 年前

rewrite 语句按顺序计算,当包含 旗帜 与URI匹配。见 this document 详情。

你应该把更具体的 正则表达式 在不太具体的问题之前。

例如:

location /category/ {
    rewrite ^(.*[^/])$ $1/ permanent;
    rewrite  ^/category/(.*)/page/(.*)/$ /index.php?slug=$1&type=category&page=$2 last;
    rewrite  ^/category/(.*)/$ /index.php?slug=$1&type=category last;
}

使 正则表达式 更具体的说,你可以使用 ([^/]+) 捕捉鼻涕虫 (\d+) 以捕获页码。