2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Moodleサイトの移行方法

Last updated at Posted at 2017-12-16

Moodleサイトの移行と問題

何らかの理由によりMoodleのサイトURLが変わる場合がある。例えばホスト名が変わった時(http://currentmoodle.yourdomain/ から http://archivemoodle.yourdomain/ )や、後で年度毎に異なるURLを使いたくなった時( http://moodle.yourdomain/ から http://moodle.yourdomain/2017/ )、HTTPSを使うように変更した時( http://moodle.yourdomain/ から https://moodle.yourdomain/ )などである。
Moodleではコンテンツ中の文字列でサイト内URLを絶対パスで保存している。そのため、これらの変更があった場合にconfig.phpの $CFG->wwwroot を変更しただけでは既存のMoodleサイト中でリンク切れとなってしまう。
この問題を解決するためにDBに保存されているURLを変換する必要がある。

対策方法

DB内のテキストをリプレースする

サイト管理者としてログインした状態で http://moodle.yourdomain/admin/tool/replace/ にアクセスすると「データベース全体のテキスト検索および置換」というページが表示される。ここで古いURLと新しいURLを指定することでデータベース内の文字列置換を行うことができる。ミスしたときのダメージが大きいので慎重に行う必要がある。

image.png

Moodle 3.4からはHTTPからHTTPSへの移行の場合に http://moodle.yourdomain/admin/tool/httpsreplace/ の「外部コンテンツURLをHTTPSにアップグレードする」というツールを利用することもできる。

image.png

Moodleのフィルタを使う

MoodleのフィルタとしてURLを置換する。単純なフィルタだがたぶん自作する必要がある。若干のシステム負荷が掛かるが、問題は起きにくい。

mod_substituteを使う

httpdを利用している場合はmod_substituteを使うことができる。nginxならnginx_substitutions_filter
AllowOverride FileInfo してあるディレクトリの中に .htaccess を置くか httpd の設定ファイル中に直接記述する。

AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|archivemoodle.yourdomain|currentmoodle.yourdomain|n"
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?