0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginxでリダイレクト時にパラメータを上書きする

Posted at

nginxでリダイレクト

nginxでリダイレクトするとき、パラメータはそのまま引き継がれてしまいます。
例えば、redirect=trueというパラメータがあったら、ルートにリダイレクトさせたいときは以下のような設定になると思います。

default.conf
if ($args ~ "redirect=true"){
	rewrite ^ / permanent;
}

その場合のリクエスト、リダイレクト後のurlは以下の様になります。

リクエストurl
http://xxx.com/111/?redirect=true
リダイレクト後url
http://xxx.com/?redirect=true

リダイレクト後のパラメータを設定する

リダイレクト後のパラメータを変更するには、リダイレクト前に$argsに値を設定すれば良いです。

default.conf
if ($args ~ "redirect=true"){
	$args = ""
	rewrite ^ / permanent;
}
リクエストurl
http://xxx.com/111/?redirect=true
リダイレクト後url
http://xxx.com/
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?