我有一个网址如下
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/