Help us understand the problem. What is going on with this article?

nginx で日本語を含むURLをリダイレクト

  • サーバー上の設定ファイルに日本語を書くとしたら文字コードをどうすればいいのか迷う
  • そもそも日本語のURLでの扱いって、どうなっていたっけ?ブラウザによって日本語で表示されていたりエンコードされていたり・・

リダイレクトの規則性があまりなく、さらに元URLが日本語を含むパスからアルファベットのパスになるなどカオスな状態。

nginxのリダイレクトは日本語URLは上手く処理できるのだけど、mapという仕組みを使うと上手くいかない感じでした。

rewriteの部分がinclude出来たので、そうすることで上手く分離出来たきがする

nginx 設定ファイル

...

map $request_uri $new{
   ~^/blog.* https://new-domain.jp/blog-new-dir/;
#  include /etc/nginx/conf.d/redirect_list.map;
}


server {
  listen 80;
  server_name 127.0.0.1;

  rewrite ^/tag(.*)/page* https://new-domain.jp/blog-new-dir/tag$1 permanent;
  rewrite ^/tag https://new-domain.jp/blog-new-dir$request_uri permanent;  

  include /etc/nginx/conf.d/rewrite_map.txt;

  if ($new) {
    rewrite ^ $new permanent;
  }
...
}

(rewrite_map.txt)
...
 rewrite ^/イギリス首相 法的性別変更について言及.* https://new-domain.jp/blog-new-dir/england-trans;
 rewrite ^/workrjr.* https://new-domain.jp/blog-new-dir/workrjr;
...

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away