我想检查nginx中的url中是否存在参数,然后重写.我可以这样做吗?
例如,如果url http://website.com/?mobile
然后将用户重定向到http://m.website.com
你最好使用http://example.com/?mobile=1
(带有值的参数).在这种情况下,检查很简单:
if ($arg_mobile) { return 302 http://m.example.com/; }
检查参数存在通常使用regexp来完成,if ($args ~ mobile)
但它容易出错,因为它会匹配mobile
任何地方,例如http://example.com/?tag=automobile
.