gpt4 book ai didi

php - 一个 url 有两个不同的路径(url 重写)

转载 作者:搜寻专家 更新时间:2023-10-31 21:24:09 25 4
gpt4 key购买 nike

我有一个网址如下

http://example.com/post/post-title/1

所以是/file-name/post-name/page-number

所以我希望第一页不显示页码。

http://example.com/post/post-title

然后从第二页开始

http://example.com/post/post-title/2

我的 htaccess 代码是。

RewriteRule post/(.*)/([0-9]+)$ post.php?id=$1&page=$2 [NC,L]

有什么办法吗?应用您的帮助。

最佳答案

你可以为此设置 2 条规则:

Options -MultiViews
RewriteEngine On

# default rule for page #1
RewriteRule post/([\w-]+)/?$ post.php?id=$1&page=1 [NC,L,QSA]

# to handle URLs with specific page #
RewriteRule post/([\w-]+)/(\d+)/?$ post.php?id=$1&page=$2 [NC,L,QSA]

关于php - 一个 url 有两个不同的路径(url 重写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com