私の個人サイト「ツムンテマの苔庭」は、この度jimdofreeドメインからtsumuntema.comという独自ドメインへ移行し、新たなスタートを切りました。その際にやった301リダイレクトの方法を書きます。
やり方
私が改めて書くよりも、私が参考にしたブログ記事を見たほうが早いです。
旧サイトのジンドゥーJimdoから新サイトURLへのリダイレクト方法
今回の独自ドメインによる新サイトへのお引越しで旧サイトとなったジンドゥー(jimdofree.com)フリー版からのリダイレクトするための設定方法がそれなりに調査したり検証を行ったので忘れないようにメモしておきます。
もっと詳しく
しかし、これで記事が終了してはつまらないので、私が実際に書いたヘッダーコードを載せておきます。
先ほどのサイトにちらっと書いていたように、javascriptで条件分岐を書き、ページごとにリダイレクト先を指定しています。
location.href の値が “https://tsumuntema.jimdofree.com/my-characters/kokeiro-kage/” だとすると、
location.hostname: “tsumuntema.jimdofree.com”
location.pathname: “/my-characters/kokeiro-kage/”
2024/06/02 追記: 末尾に「/」を入れたときと入れないとき、両方の指定をする必要があったため修正しました。
<link rel="canonical" href="https://tsumuntema.com/" />
<script type="text/javascript">
//<![CDATA[
if(location.hostname == 'tsumuntema.jimdofree.com'){
setTimeout("link()", 0);
function link(){
if(location.pathname == '/'){
//ルート
location.href='https://tsumuntema.com/';
}else if(location.pathname == '/discography'){
//ディスコグラフィー
location.href='https://tsumuntema.com/discography/';
}else if(location.pathname == '/discography/'){
//ディスコグラフィー
location.href='https://tsumuntema.com/discography/';
}else if(location.pathname == '/bandbros-p-distribution'){
//バンブラP配信曲
location.href='https://tsumuntema.com/bbp-distribution/';
}else if(location.pathname == '/bandbros-p-distribution/'){
//バンブラP配信曲
location.href='https://tsumuntema.com/bbp-distribution/';
}else if(location.pathname == '/cover'){
//カバー曲
location.href='https://tsumuntema.com/cover/';
}else if(location.pathname == '/cover/'){
//カバー曲
location.href='https://tsumuntema.com/cover/';
}else if(location.pathname == '/cover/bandbros-p'){
//カバー曲 - バンブラP
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/'){
//カバー曲 - バンブラP
location.href='https://tsumuntema.com/cover/bbp/';
//分割ページを全て/cover/bbp/にリダイレクトする
}else if(location.pathname == '/cover/bandbros-p/1'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/1/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/2'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/2/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/3'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/3/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/4'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/4/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/5'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/5/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/6'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/6/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/7'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-p/7/'){
location.href='https://tsumuntema.com/cover/bbp/';
}else if(location.pathname == '/cover/bandbros-dx'){
//カバー曲 - バンブラDX
location.href='https://tsumuntema.com/cover/bdx/';
}else if(location.pathname == '/cover/bandbros-dx/'){
//カバー曲 - バンブラDX
location.href='https://tsumuntema.com/cover/bdx/';
}else if(location.pathname == '/cover/petitcom2'){
//カバー曲 - プチコンmkII
location.href='https://tsumuntema.com/cover/ptcm2/';
}else if(location.pathname == '/cover/petitcom2/'){
//カバー曲 - プチコンmkII
location.href='https://tsumuntema.com/cover/ptcm2/';
}else if(location.pathname == '/cover/petitcom3'){
//カバー曲 - プチコン3号
location.href='https://tsumuntema.com/cover/ptcm3/';
}else if(location.pathname == '/cover/petitcom3/'){
//カバー曲 - プチコン3号
location.href='https://tsumuntema.com/cover/ptcm3/';
}else if(location.pathname == '/cover/korg-gadget'){
//カバー曲 - KORG Gadget
location.href='https://tsumuntema.com/cover/korg-gadget/';
}else if(location.pathname == '/cover/korg-gadget/'){
//カバー曲 - KORG Gadget
location.href='https://tsumuntema.com/cover/korg-gadget/';
}else if(location.pathname == '/cover/korg-m01d'){
//カバー曲 - KORG M01D
location.href='https://tsumuntema.com/cover/korg-m01d/';
}else if(location.pathname == '/cover/korg-m01d/'){
//カバー曲 - KORG M01D
location.href='https://tsumuntema.com/cover/korg-m01d/';
}else if(location.pathname == '/cover/warioware-diy'){
//カバー曲 - メイドイン俺
location.href='https://tsumuntema.com/cover/warioware-diy/';
}else if(location.pathname == '/cover/warioware-diy/'){
//カバー曲 - メイドイン俺
location.href='https://tsumuntema.com/cover/warioware-diy/';
}else if(location.pathname == '/cover/legacy-midi'){
//カバー曲 - MIDI
location.href='https://tsumuntema.com/cover/legacy-midi/';
}else if(location.pathname == '/cover/legacy-midi/'){
//カバー曲 - MIDI
location.href='https://tsumuntema.com/cover/legacy-midi/';
}else if(location.pathname == '/cover/daw'){
//カバー曲 - DAW
location.href='https://tsumuntema.com/cover/daw/';
}else if(location.pathname == '/cover/daw/'){
//カバー曲 - DAW
location.href='https://tsumuntema.com/cover/daw/';
}else if(location.pathname == '/my-characters'){
//キャラクター
location.href='https://tsumuntema.com/character/';
}else if(location.pathname == '/my-characters/'){
//キャラクター
location.href='https://tsumuntema.com/character/';
}else if(location.pathname == '/my-characters/kokeiro-kage'){
//苔色かげ
location.href='https://tsumuntema.com/character/kage/';
}else if(location.pathname == '/my-characters/kokeiro-kage/'){
//苔色かげ
location.href='https://tsumuntema.com/character/kage/';
}else if(location.pathname == '/my-characters/kareiro-yamo'){
//枯色ヤモ
location.href='https://tsumuntema.com/character/yamo/';
}else if(location.pathname == '/my-characters/kareiro-yamo/'){
//枯色ヤモ
location.href='https://tsumuntema.com/character/yamo/';
}else if(location.pathname == '/my-characters/term-of-use'){
//利用規約
location.href='https://tsumuntema.com/character/terms-of-use/';
}else if(location.pathname == '/my-characters/term-of-use/'){
//利用規約
location.href='https://tsumuntema.com/character/terms-of-use/';
}else if(location.href == 'https://tsumuntema.jimdofree.com/my-characters/term-of-use#derivative-works'){
//利用規約 - 二次創作について
location.href='https://tsumuntema.com/character/terms-of-use/#derivative-works';
}else if(location.href == 'https://tsumuntema.jimdofree.com/my-characters/term-of-use#mycoe'){
//利用規約 - MYCOEIROINK
location.href='https://tsumuntema.com/character/terms-of-use/#mycoe';
}else if(location.pathname == '/tsumulog'){
//ブログ
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/'){
//ブログ
location.href='https://tsumuntema.com/blog/';
//年ごとのブログページを全て/blog/にリダイレクト
}else if(location.pathname == '/tsumulog/2021'){
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/2021/'){
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/2022'){
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/2022/'){
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/2023'){
location.href='https://tsumuntema.com/blog/';
}else if(location.pathname == '/tsumulog/2023/'){
location.href='https://tsumuntema.com/blog/';
//個別の記事をリダイレクト
}else if(location.pathname == '/2021-12-22-windowsupdate'){
location.href='https://tsumuntema.com/windows-update/';
}else if(location.pathname == '/2021-12-22-windowsupdate/'){
location.href='https://tsumuntema.com/windows-update/';
}else if(location.pathname == '/2021-12-24-ssl2plus'){
location.href='https://tsumuntema.com/ssl2plus/';
}else if(location.pathname == '/2021-12-24-ssl2plus/'){
location.href='https://tsumuntema.com/ssl2plus/';
}else if(location.pathname == '/2022-09-18-windows11-install-2nd'){
location.href='https://tsumuntema.com/windows11-install/';
}else if(location.pathname == '/2022-09-18-windows11-install-2nd/'){
location.href='https://tsumuntema.com/windows11-install/';
}else if(location.pathname == '/2022-10-12-ita-corpus'){
location.href='https://tsumuntema.com/ita-corpus-recording/';
}else if(location.pathname == '/2022-10-12-ita-corpus/'){
location.href='https://tsumuntema.com/ita-corpus-recording/';
}else if(location.pathname == '/2022-11-15-rx6600xt'){
location.href='https://tsumuntema.com/rx6600xt/';
}else if(location.pathname == '/2022-11-15-rx6600xt/'){
location.href='https://tsumuntema.com/rx6600xt/';
}else if(location.pathname == '/2022-11-16-ryzen-5-5600'){
location.href='https://tsumuntema.com/ryzen5-5600/';
}else if(location.pathname == '/2022-11-16-ryzen-5-5600/'){
location.href='https://tsumuntema.com/ryzen5-5600/';
}else if(location.pathname == '/2023-01-04-dg-stk1b'){
location.href='https://tsumuntema.com/dg-stk1b/';
}else if(location.pathname == '/2023-01-04-dg-stk1b/'){
location.href='https://tsumuntema.com/dg-stk1b/';
}else if(location.pathname == '/link'){
//リンク集
location.href='https://tsumuntema.com/link/';
}else if(location.pathname == '/link/'){
//リンク集
location.href='https://tsumuntema.com/link/';
}else{
//条件に合致しなかったページを全てルートへリダイレクト
location.href='https://tsumuntema.com/';
}
}
}
//]]>
</script>
コメント