LoginSignup
2
4

More than 5 years have passed since last update.

nginxでGETパラメータの値を使用してリダイレクト先のURLを作成する方法

Posted at

GETパラメータの値を使用してリダイレクト先のURLを作成する方法

旧サイトから新サイトへ移行する際に、新サイトのパッケージの都合でカテゴリーページ、個別ページのURLが変更になった時に行なったnginxの設定メモ

・ECサイトにおける商品カテゴリーページ、商品個別ページの旧サイト→新サイト設定例

nginx.conf
server {
#~~~~~~~~~~~~~省略~~~~~~~~~~~~~~~

    #商品カテゴリーページ例
    # 旧サイトURL: https://xxxxxxx.jp/products/list.php?category_id=1
    # ↓
    # 新サイトURL: https://xxxxxxx.jp/products/cat1/
    #
    if ($args ~ "category_id=(.*)") {
        set $category_id $1;
        rewrite ^/products/list.php.*$ /products/cat$category_id/? permanent;
    }

    #商品個別ページ例
    # 旧サイトURL: https://xxxxxxx.jp/products/detail.php?product_id=1
    # ↓
    # 新サイトURL: https://xxxxxxx.jp/product/1/
    #
    if ($args ~ "product_id=(.*)") {
        set $product_id $1;
        rewrite ^/products/detail.php.*$ /product/$product_id/? permanent;
    }

#~~~~~~~~~~~~~省略~~~~~~~~~~~~~~~
}


2
4
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
2
4