删除nginx重写中的参数 [英] Remove parameters within nginx rewrite
问题描述
http://www.example.com/mypage .php?type = 4
新页面没有这些参数。我想删除它们并将URL重写到主页面,以便我得到:
http://www.example .com / mypage /
我在nginx中的重写规则是:
位置^〜/mypage.php {
重写^ / mypage.php $ http://www.example.com/mypage永久;
}
但是通过这个规则,参数仍然被追加。我认为 $
会阻止nginx处理更多的值......任何想法?所有其他问题处理如何添加参数 - 我只是想删除我的:)
有一个类似的问题,后很多搜索答案出现在重写文档中。
如果你指定一个?在重写结束后,Nginx将放弃原始的$ args(参数)。
因此,对于您的示例,这可以解决这个问题:
位置^〜/mypage.php {
重写^ / mypage.php $ http:// www。 example.com/mypage?常驻;
}
I'm rewriting URLs in nginx after a relaunch. In the old site I had query parameters in the URL to filter stuff e.g.
http://www.example.com/mypage.php?type=4
The new page doesn't have these kind of parameters. I want to remove them and rewrite the URLs to the main page, so that I get:
http://www.example.com/mypage/
My rewrite rule in nginx is:
location ^~ /mypage.php {
rewrite ^/mypage.php$ http://www.example.com/mypage permanent;
}
But with this rule the parameter is still appended. I thought the $
would stop nginx from processing further values... any ideas? All other questions deal with how to add parameters - I just want to remove mine :)
Had a similar problem, after a lot of searching the answer presented itself in the rewrite docs.
If you specify a ? at the end of a rewrite then Nginx will drop the original $args (arguments)
So for your example, this would do the trick:
location ^~ /mypage.php {
rewrite ^/mypage.php$ http://www.example.com/mypage? permanent;
}
这篇关于删除nginx重写中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!