试图让 http://example.com/shop/donate?id=123 重定向到 http://example.com/donate/123Nginx的重写基本的正则表达式
随着低于我的.conf,打顶URL不会导致重定向。 .conf中的其他重定向正在工作。有什么想法吗?
server{
....
rewrite ^/shop/donate?id=([0-9]+)$ /donate/$1 permanent;
}
试图让 http://example.com/shop/donate?id=123 重定向到 http://example.com/donate/123Nginx的重写基本的正则表达式
随着低于我的.conf,打顶URL不会导致重定向。 .conf中的其他重定向正在工作。有什么想法吗?
server{
....
rewrite ^/shop/donate?id=([0-9]+)$ /donate/$1 permanent;
}
你需要躲避问号,否则它就会被解析为正则表达式:
server{
....
rewrite ^/shop/donate\?id=([0-9]+)$ /donate/$1 permanent;
}
我补充说,仍然没有重定向 – cactusphone 2015-04-01 20:46:58
Nginx的重写仅适用于URL的_path_部分 – 2015-04-02 07:25:42
您可以尝试使用$ arg_ [名]这种情况:
rewrite ^/shop/donate$ /donate/$arg_id;
为什么会你要这个?可能你的应用程序会更好地重定向。 – 2015-04-02 07:26:36