0
3

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.

Wordpressと、ルートのindex.htmlを共存させる方法

0
Last updated at Posted at 2017-01-12

Wordpressを設置するには、index.phpを置く必要がありますが、
設置ディレクトリ上にindex.htmlが既にある場合、サーバーの設定でHTML(index.html)が優先されてしまいます。
この場合、WPのindex.phpが動かないので、WPは動作しません。
ただ、トップページにindex.htmlを置きながら、WPのデザイン確認などしたい場合などあると思います。
そんな場合の解決法を考えてみました。

解決策1: WPのテーマ内からindex.htmlをロードする。

ルートのindex.htmlをindex_wp.htmlなどにリネームします。
その上で、WPテーマ内のindex.phpからindex_wp.htmlをロードします。

index.php
<?php

$topurl = home_url( '/index_wp.html' );
$data = file_get_contents($topurl, false, $context);
echo $data;

こうすることで、トップページはindex.htmlのソースを読むという体裁を保ったまま、WPと共存させることができます。

ただし、読み込む順番が
アクセス→index.php読み込み→wpディレクトリの転送用テーマ読み込み→rootのindex_wp.htmlを読み込み
となってしまうため、表示速度に若干影響が出ます。

解決策2: サーバーの設定を変更

サーバーのDirectoryIndexを変更し、ルートのindex.phpが先に読まれるようにした上で、index.phpに以下のコードを追加します。

index.php
<?php 
if( $_SERVER['HTTP_HOST'] == 'example.com' ) {
   include 'index.html';
   exit();
}

影響範囲が少ない1.の方がスマートかもしれません。

参考
https://dogmap.jp/2009/10/20/view-index-html/
https://ja.wordpress.org/support/topic/%E8%A6%AA%E3%83%89%E3%83%A1%E3%82%A4%E3%83%B3%E3%81%ABindex-php%E3%82%92%E7%BD%AE%E3%81%8B%E3%81%AA%E3%81%84%E6%96%B9%E6%B3%95/

0
3
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
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?