Rewrite

「a」や「img」のリンク先のURLを書き換えるプラグインです。

インストール手順

ダウンロード

ダウンロードページからプラグインをダウンロードします。「src.zip」と「src.tar.gz」は開発者向けのファイルなので、プラグインを利用する場合は「src」の付かないファイルをダウンロードしてください。

ファイルの設置

ダウンロードしたファイルを展開して「ckeditor/plugins/rewrite」をインストール先の「ckeditor/plugins/」の下へ設置してください。

読み込むプラグインの追加

ckeditor/config.js で config.extraPlugins へ rewrite を追加してください。(設定例) (ドキュメント)

ツールバーへのボタンの追加

ckeditor/config.js で変換のルールを指定します。

ckeditor/config.js の設定例 (デフォルトの値を使う)

CKEDITOR.editorConfig = function(config) {
    config.extraPlugins = 'rewrite';

    // rewrite の機能を有効にします。
    config.rewrite_urls = true;
    // デフォルトではホストからの相対パスに書き換えます。
}

ckeditor/config.js の設定例 (細かく指定する)

CKEDITOR.editorConfig = function(config) {
    config.extraPlugins = 'rewrite';

    // rewrite の機能を有効にします。
    config.rewrite_urls = true;

    config.rewrite_rules = {
        a: {
            href: {
                // http://example.com/のファイルを相対パスへ書き換え
                from: 'http://example.com/',
                to: ''
            }
        },
        img: {
            src: {
                // http://foo.example.com/を
                // http://bar.example.com/へ書き換え
                from: 'http://foo.example.com/',
                to: 'http://bar.example.com/'
            }
        }
    };
}

ckeditor/config.js の設定例 (まとめて指定する)

CKEDITOR.editorConfig = function(config) {
    config.extraPlugins = 'rewrite';

    // rewrite の機能を有効にします。
    config.rewrite_urls = true;

    // 書換え元のURLを指定します
    config.rewrite_default_from = 'https?://foo.example.com/(img|css)';
    // 書換え先のURLを指定します
    config.rewrite_default_to = 'http://bar.example.com/$1';
}