マルチサイト化したWordPressでDB内のサイトURLをhttpからhttpsに変更する
マルチサイト化したWordPress環境は以下のテーブルにスキーマ込みのURLを持っている wp_sitemeta
wp_options
wp_{id}_options
マルチサイトの数だけテーブルが存在
確認
code: select.sql
select * from wp_sitemeta where meta_key = "siteurl";
select * from wp_options where option_name in ("siteurl", "home");
select * from wp_1_options where option_name in ("siteurl", "home");
書き換え
code: replace.sql
update wp_sitemeta set meta_value=REPLACE(meta_value, 'http:', 'https:') where meta_key = "siteurl";
update wp_options set option_value=REPLACE(option_value, 'http:', 'https:') option_name in ("siteurl", "home");
update wp_1_options set option_value=REPLACE(option_value, 'http:', 'https:') where option_name in ("siteurl", "home");
余談
コロン抜きのhttpを対象に置換を実行すると、置換後のhttpsも置換対象になって冪等性がないのでコロンも対象
文法的にも合ってる
プロトコルとしてhttp://が1つのかたまりのように説明される場合があるがこれは間違い
RFC3986を見る
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
なので//はhier-partの接頭語
hier-part = "//" authority path-abempty
//はwwwの生みの親のTim Berners-Leeさんに、要らんかったわと言われている