vBulletin から Discourse へ移行中で、古い vBulletin の URL を新しい Discourse の URL にリダイレクトしたいですか?続けてお読みください!
もし古いフォーラムと新しいフォーラムのベース URL が同じ場合は、代わりに以下のハウツーに従ってください:
Redirect old forum URLs to new Discourse URLs using permalinks
このハウツーでは、以下を前提としています:
- vBulletin のベース URL:
www.example.com/forum - Discourse のベース URL:
forum.example.com www.example.com用の Nginx サーバー
始めましょう!
Nginx マップファイルの生成
カテゴリとトピックのリダイレクトを設定するには、Nginx の map モジュールを使用します。CSV ファイルは、create_permalink_file メソッドを使用してインポートを実行する際に生成されます(script/import_scripts/vb_map.csv)。この CSV ファイルの内容をサーバー上のマップファイルに貼り付けます。
ファイルのサンプル内容:
...
/forum/forumdisplay.php?6 http://forum.example.com/c/games;
/forum/forumdisplay.php?7 http://forum.example.com/c/movies;
/forum/forumdisplay.php?13 http://forum.example.com/c/admin;
/forum/showthread.php?1 http://forum.example.com/t/x/22;
/forum/showthread.php?2 http://forum.example.com/t/x/23;
/forum/showthread.php?3 http://forum.example.com/t/x/24;
/forum/showthread.php?4 http://forum.example.com/t/x/25;
...
生成された CSV ファイルの全内容を、www.example.com サーバー上の etc/nginx/vb_forum.map にコピーしてください。
nginx.conf の編集
/etc/nginx/nginx.conf ファイルを編集して、http ブロックに以下のコードを追加します:
map_hash_bucket_size 128;
map_hash_max_size 80000;
map $request_uri $new {
include /etc/nginx/vb_forum.map;
}
server {
listen 80;
server_name www.example.com;
location ~ ^/forum\\/showthread.php {
if ($args ~* ^(\\d+)-(.+)$) {
set $tid $1;
set $args '';
rewrite ^ /forum/showthread.php?$tid permanent;
}
if ($args ~* ^t=(\\d+)$) {
set $tid $1;
set $args '';
rewrite ^ /forum/showthread.php?$tid permanent;
}
return 301 http://forum.example.com;
}
location ~ ^/forum\\/forumdisplay.php {
if ($args ~* ^(\\d+)-(.+)$) {
set $tid $1;
set $args '';
rewrite ^ /forum/forumdisplay.php?$tid permanent;
}
if ($args ~* ^f=(\\d+)$) {
set $tid $1;
set $args '';
rewrite ^ /forum/forumdisplay.php?$tid permanent;
}
return 301 http://forum.example.com;
}
if ($new) {
rewrite ^ $new permanent;
}
location /forum {
return 301 http://forum.example.com;
}
}
map_hash_max_size は、マップファイルに含まれる URL の数に応じて調整する必要があります。
nginx.conf の検証
Nginx 設定ファイルを検証します:
nginx -c /etc/nginx/nginx.conf -t
変更を反映させるために Nginx 設定をリロードします:
sudo systemctl reload nginx
www.example.com/forum にアクセスしてみてください。これで forum.example.com にリダイレクトされるはずです。![]()
上記の Nginx 設定で処理される URL の種類は以下の通りです:
www.example.com/forum→forum.example.comwww.example.com/forum/forumdisplay.php?6→forum.example.com/c/gameswww.example.com/forum/forumdisplay.php?6-Games→forum.example.com/c/gameswww.example.com/forum/forumdisplay.php?f=6→forum.example.com/c/gameswww.example.com/forum/showthread.php?2→forum.example.com/t/topic-slug/23www.example.com/forum/showthread.php?2-topic-slug→forum.example.com/t/topic-slug/23www.example.com/forum/showthread.php?t=2→forum.example.com/t/topic-slug/23