设置 dir/page/page 重定向与 dir/page 不同?

Setting dir/page/page redirect distinct from dir/page?

我有一些 .htaccess 重写规则如下:

RewriteRule name/john item.php?id=1 [NC,L,QSA]
RewriteRule name/jill item.php?id=2 [NC,L,QSA]

在上面的页面上,我想 link 到 name/john/profile 之类的东西。我试过以下规则:

RewriteRule name/john/profile profile.php?id=1 [NC,L,QSA]
RewriteRule name/jill/profile profile.php?id=2 [NC,L,QSA]

但是单击这些 link 会重定向到 item.php,而不是 profile.php

更深层次的规则是不可能的还是我错过了一个标志?

您可以使用:

RewriteRule ^name/john/?$ item.php?id=1 [NC,L,QSA]
RewriteRule ^name/jill/?$ item.php?id=2 [NC,L,QSA]
RewriteRule ^name/john/profile/?$ profile.php?id=1 [NC,L,QSA]
RewriteRule ^name/jill/profile/?$ profile.php?id=2 [NC,L,QSA]

我喜欢添加 /? 因为无论有没有最终 /