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


One url with two different paths (url rewriting)

我有一个url如下

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]

有什么办法可以做到吗?应用你的帮助

你可以有两个规则:

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]