避免 dir mod 重写

发布于 2024-09-13 05:03:38 字数 342 浏览 2 评论 0原文

我有这样的规则:

RewriteRule ^posts/(.*)/([0-9]*)$ viewupdates.php?username=$1&page=$2 [L]

并匹配: http://site.com/posts/username/1

我需要念诵:

http://site.com/username/posts

没有尾部斜杠,如果有更多页面/posts/1

i have a rule like this:

RewriteRule ^posts/(.*)/([0-9]*)$ viewupdates.php?username=$1&page=$2 [L]

and match to: http://site.com/posts/username/1

i need to chante to:

http://site.com/username/posts

without trailing slash, and if have more pages /posts/1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2024-09-20 05:03:38

只需转置后一种情况的正则表达式的相应部分:

RewriteRule ^(.*)/posts/([0-9]*)$ viewupdates.php?username=$1&page=$2 [L]

可能,您还需要另一个没有额外“页面”规范的规则(对于您描述的前一种情况),像这样:

RewriteRule ^(.*)/posts$ viewupdates.php?username=$1 [L]

或者

RewriteRule ^(.*)/posts$ viewupdates.php?username=$1&page=1 [L]

取决于您的脚本实现。

Simply transpose the corresponding parts of the regexp for the latter case:

RewriteRule ^(.*)/posts/([0-9]*)$ viewupdates.php?username=$1&page=$2 [L]

Probably, you also want another rule without the extra "page" specification (for the former case you describe), smth like this:

RewriteRule ^(.*)/posts$ viewupdates.php?username=$1 [L]

or

RewriteRule ^(.*)/posts$ viewupdates.php?username=$1&page=1 [L]

depending on your implementation of the script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文