54
38

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でURLに渡すパラメータのメモ

Last updated at Posted at 2016-03-07

いつものように個人的なメモ

URLにパラメータを付与した際の動作
hoge.jp へのアクセスを foo.jp へ飛ばすと想定

関連:Nginxのリダイレクト設定のメモ

1. 何も無し

  location / {
    rewrite ^(.*)$ http://foo.jp redirect;
  }

hoge.jp?bar -> foo.jp/?bar となる

2. $request_uri

  location / {
    rewrite ^(.*)$ http://foo.jp$request_uri redirect;
  }

hoge.jp?bar -> foo.jp/?bar?bar となる

3. $uri

  location / {
    rewrite ^(.*)$ http://foo.jp$uri redirect;
  }

hoge.jp?bar -> foo.jp/?bar となる

4. $uri$args

  location / {
    rewrite ^(.*)$ http://foo.jp$uri$args redirect;
  }

hoge.jp?bar -> foo.jp/bar?bar となる

5. $uri?$args

  location / {
    rewrite ^(.*)$ http://foo.jp$uri?$args redirect;
  }

hoge.jp?bar -> foo.jp/?bar&bar となる

6. ?止め

  location / {
    rewrite ^(.*)$ http://foo.jp? redirect;
  }

hoge.jp?bar -> foo.jp/ となる

7. set $args '';

  location / {
    set $args '';
    rewrite ^(.*)$ http://foo.jp$request_uri redirect;
  }

hoge.jp?bar -> foo.jp/?bar となる

メモ

動作に差がでるので注意

参考

ようへいの日々精進XP: 深夜メンテナンスに役立ちそうな nginx 小ネタ
stackoverflow: Remove parameters within nginx rewrite

54
38
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
54
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?