get - 删除 nginx 重写中的参数

标签 get nginx url-rewriting

重新启动后我正在重写 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/

相关文章:

apache - HTAccess 将目录格式重写为查询字符串

nginx - 如果应用程序映射到子目录,如何在 Nginx + Flask 设置中加载静态文件

c# - 如何修复 UNITYTLS_X509VERIFY_NOT_DONE

asp.net - 如何删除www. ASP.NET MVC 中的前缀

java - 获取当前设置的内容 View

nginx - 如何在 nginx Web 服务器的重写规则中将大写字母转换为小写字母?

.htaccess 重写 php 分页

http - Arduino 模块 esp8266 返回错误请求

node.js - 如何确保 NodeJS 在错误请求后恢复?

android - 如何访问 android 彩信资源,如视频/音频等?