gpt4 book ai didi

apache - 用于 Apache 重写的 Nginx 重写 URL 替换

转载 作者:行者123 更新时间:2023-12-02 05:09:53 24 4
gpt4 key购买 nike

如何为以下内容转换 nginx 等效的 URL 重写:

RewriteRule ^read/([0-9]+)/?$ /read/?u=$1 [QSA,L]

最佳答案

您可以通过两种方式执行此操作,使用一个位置:

# the ?<u> assigns the capture to $u.  Some older pcres need ?P<u>
location ^/read/(?<u>[0-9]+)/?$ {
rewrite ^ /read/?u=$u last;
}

或者只是重写:

rewrite ^/read/([0-9]+)/?$ /read/?u=$1 last;

nginx 默认会附加查询字符串(您可以通过在重写目标末尾添加另一个 ? 来禁用该行为)。

关于apache - 用于 Apache 重写的 Nginx 重写 URL 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6825111/

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