• 解決済 tokkonopapa

    (@tokkonopapa)


    公式に公開中のプラグイン検証用環境として、サブディレクトリ型とサブドメイン型のマルチサイトを MAMP で構築しています。

    現状、リンク先の画像にある様に両者が混在している状態で、それぞれダッシュボード、公開ページとも、正しく動作している様に見えています。

    https://raw.githubusercontent.com/tokkonopapa/WordPress-IP-Geo-Block/gh-pages/img/2016-05/multisite.png

    ただ通常はこのような事は出来ないのでは?と思っています。それ故、この環境が正しいかどうか、ご意見を頂ければ幸いです。

    ローカルの環境は以下の通りです。

    サーバー

    • MAMP PRO 3.5
    • Apache 2.2.29
    • 仮想ホスト local.example.com を設定
    • /etc/hosts で local.example.com を 127.0.0.1 に設定
    • ドキュメントルートは localhost と共通に設定
    • SSL を自己署名付き証明書で設定
    • PHP 5.6.10

    WordPress

    1. http://localhost Twenty Twelve の子テーマを適用、言語設定は英語
    2. http://localhost/site WpTHK の子テーマを適用、言語設定は日本語
    3. http://local.example.com Twenty Sixteen の子テーマを適用、言語設定は英語、ただし、一旦 サブディレクトリ型として作成した後に、サイト URL を変更(← ドキュメントには載ってないやり方で、怪しいところ)

    wp-config.php への追加

    // https://codex.wordpress.org/Debugging_in_WordPress
    define('WP_DEBUG', true);
    if ( WP_DEBUG ) {
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', false );
        @ini_set( 'display_errors', 0 );
    }
    
    /* Multisite */
    define('WP_ALLOW_MULTISITE', true);
    define('MULTISITE', true);
    if ( MULTISITE ) {
        define('SUBDOMAIN_INSTALL', false);
        define('DOMAIN_CURRENT_SITE', 'localhost');
        define('PATH_CURRENT_SITE', '/');
        define('SITE_ID_CURRENT_SITE', 1);
        define('BLOG_ID_CURRENT_SITE', 1);
    }
    
    /* Admin SSL */
    define('FORCE_SSL_ADMIN', false);

    .htaccess はサブディレクトリ型を適用
    http://codex.wordpress.org/Multisite_Network_Administration#.htaccess_and_Mod_Rewrite を見ると、サブディレクトリ型の方が汎用性があるため。またサブドメイン型の下から2行目 RewriteRule ^(.*\.php)$ wp/$1 [L] は、wp-admin/includes/network.php のコードから、誤りがあると判断。

    各サイトのテンプレート・タグの結果

    1. http://localhost/

    home_url():                     http://localhost
    network_home_url():             http://localhost/
    get_home_url():                 http://localhost
    site_url():                     http://localhost
    network_site_url():             http://localhost/
    admin_url():                    http://localhost/wp-admin/
    network_admin_url():            http://localhost/wp-admin/network/
    includes_url():                 http://localhost/wp-includes/
    content_url():                  http://localhost/wp-content
    plugins_url():                  http://localhost/wp-content/plugins
    get_template_directory_uri():   http://localhost/wp-content/themes/twentytwelve
    get_stylesheet_directory_uri(): http://localhost/wp-content/themes/twentytwelve-child
    get_stylesheet_uri():           http://localhost/wp-content/themes/twentytwelve-child/style.css
    get_template_directory():       /Applications/MAMP/htdocs/wp-content/themes/twentytwelve
    get_stylesheet_directory():     /Applications/MAMP/htdocs/wp-content/themes/twentytwelve-child
    get_theme_root():               /Applications/MAMP/htdocs/wp-content/themes
    get_theme_root_uri():           http://localhost/wp-content/themes
    wp_upload_dir():
    Array
    (
        [path] => /Applications/MAMP/htdocs/wp-content/uploads/2016/05
        [url] => http://localhost/wp-content/uploads/2016/05
        [subdir] => /2016/05
        [basedir] => /Applications/MAMP/htdocs/wp-content/uploads
        [baseurl] => http://localhost/wp-content/uploads
        [error] =>
    )

    2. http://localhost/site/

    home_url():                     http://localhost/site
    network_home_url():             http://localhost/
    get_home_url():                 http://localhost/site
    site_url():                     http://localhost/site
    network_site_url():             http://localhost/
    admin_url():                    http://localhost/site/wp-admin/
    network_admin_url():            http://localhost/wp-admin/network/
    includes_url():                 http://localhost/site/wp-includes/
    content_url():                  http://localhost/site/wp-content
    plugins_url():                  http://localhost/site/wp-content/plugins
    get_template_directory_uri():   http://localhost/site/wp-content/themes/wpthk
    get_stylesheet_directory_uri(): http://localhost/site/wp-content/themes/wpthk-child
    get_stylesheet_uri():           http://localhost/site/wp-content/themes/wpthk-child/style.css
    get_template_directory():       /Applications/MAMP/htdocs/wp-content/themes/wpthk
    get_stylesheet_directory():     /Applications/MAMP/htdocs/wp-content/themes/wpthk-child
    get_theme_root():               /Applications/MAMP/htdocs/wp-content/themes
    get_theme_root_uri():           http://localhost/site/wp-content/themes
    wp_upload_dir():
    Array
    (
        [path] => /Applications/MAMP/htdocs/wp-content/uploads/sites/2/2016/05
        [url] => http://localhost/site/wp-content/uploads/sites/2/2016/05
        [subdir] => /2016/05
        [basedir] => /Applications/MAMP/htdocs/wp-content/uploads/sites/2
        [baseurl] => http://localhost/site/wp-content/uploads/sites/2
        [error] =>
    )

    3. http://local.example.com/

    home_url():                     http://local.example.com
    network_home_url():             http://localhost/
    get_home_url():                 http://local.example.com
    site_url():                     http://local.example.com
    network_site_url():             http://localhost/
    admin_url():                    http://local.example.com/wp-admin/
    network_admin_url():            http://localhost/wp-admin/network/
    includes_url():                 http://local.example.com/wp-includes/
    content_url():                  http://local.example.com/wp-content
    plugins_url():                  http://local.example.com/wp-content/plugins
    get_template_directory_uri():   http://local.example.com/wp-content/themes/twentysixteen
    get_stylesheet_directory_uri(): http://local.example.com/wp-content/themes/twentysixteen-child
    get_stylesheet_uri():           http://local.example.com/wp-content/themes/twentysixteen-child/style.css
    get_template_directory():       /Applications/MAMP/htdocs/wp-content/themes/twentysixteen
    get_stylesheet_directory():     /Applications/MAMP/htdocs/wp-content/themes/twentysixteen-child
    get_theme_root():               /Applications/MAMP/htdocs/wp-content/themes
    get_theme_root_uri():           http://local.example.com/wp-content/themes
    wp_upload_dir():
    Array
    (
        [path] => /Applications/MAMP/htdocs/wp-content/uploads/sites/3/2016/05
        [url] => http://local.example.com/wp-content/uploads/sites/3/2016/05
        [subdir] => /2016/05
        [basedir] => /Applications/MAMP/htdocs/wp-content/uploads/sites/3
        [baseurl] => http://local.example.com/wp-content/uploads/sites/3
        [error] =>
    )

    長文、失礼しました。よろしくお願いします m_(..)_m

3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「ローカル環境マルチサイト:サブディレクトリとサブドメインの混在」には新たに返信することはできません。