我如何将带有查询字符串的网址重定向到NgInX中没有查询字符串的网址?

时间:2012-10-09 14:33:53

标签: redirect nginx rewrite

我需要将包含查询字符串的url重定向/重写到同一个url,但没有查询字符串。例如http://domain.com/a-post-title/?fbid=xyzhttp://domain.com/a-post-title/ 抱歉我的英语不好。

1 个答案:

答案 0 :(得分:3)

很简单,只需在重写结束时加?, 来自http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

If a replacement string includes the new request arguments, the previous request 
arguments are appended after them. If this is undesired, putting a question mark at the 
end of a replacement string avoids having them appended