LoginSignup
0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-09-08
  • サーバー上の設定ファイルに日本語を書くとしたら文字コードをどうすればいいのか迷う
  • そもそも日本語の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;
...

0
0
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
0