WordPressをドキュメントルート配下のサブディレクトリに設置する | WordPress
概要
ドキュメントルートにディレクトリ(名前は任意)を作成してインストールしたWordPressを、ドキュメントルート直下で動作させる。
サイトのホームページとWordPressインストールディレクトリ
以下の例でsiteurlとhomeの関連を記載する。
| 管理画面 | wp_options | define(wp-config.php) | 値 |
|---|---|---|---|
| WordPress アドレス (URL) | siteurl | WP_SITEURL | https://example.com/wordpress |
| サイトアドレス (URL) | home | WP_HOME | https://example.com |
配置
|-DocumentRoot
|
|-- index.php
|
|-- .htaccess
|
|-- wordpress
|
|...
|
|-- wp-content
|
|...
手順
- 管理画面 > 設定 > 一般設定で以下を設定
- WordPress アドレス (URL):
https://example.com/wordpress - サイトアドレス (URL):
https://example.com/
- WordPress アドレス (URL):
index.php、.htaccessをドキュメントルートに移動index.phpを修正- 管理画面 > 設定 > パーマリンク設定で「変更を保存」をクリック(リライトルールを再生成するため)
index.php
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
- require __DIR__ . '/wp-blog-header.php';
+ require __DIR__ . '/wordpress/wp-blog-header.php';
基本的な配置(wp_optionsの値)
| option_id | option_name | option_value |
|---|---|---|
| 1 | siteurl | https://example.com/wordpress |
| 2 | home | https://example.com/ |