重新启动后我正在重写 nginx 中的 URL。在旧网站中,我在 URL 中有查询参数来过滤内容,例如
http://www.example.com/mypage.php?type=4
新页面没有此类参数。我想删除它们并重写主页的 URL,这样我就得到:
http://www.example.com/mypage/
我在nginx中的重写规则是:
location ^~ /mypage.php {
rewrite ^/mypage.php$ http://www.example.com/mypage permanent;
}
但根据此规则,参数仍会附加。我认为 $
会阻止 nginx 处理进一步的值...有什么想法吗?所有其他问题都涉及如何添加参数 - 我只想删除我的:)
最佳答案
有一个类似的问题,经过大量搜索后,答案出现在rewrite docs中.
If you specify a ? at the end of a rewrite then Nginx will drop the original $args (arguments)
因此,对于您的示例,这可以解决问题:
location ^~ /mypage.php {
rewrite ^/mypage.php$ http://www.example.com/mypage? permanent;
}
关于get - 删除 nginx 重写中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9641603/