マルチサイト子サイトの管理画面wp-adminのみにbasic認証をかける

※あまりうまく行かないので検証が必要

まず、前に書いたサイトや管理画面含めて全部にかける方法。

これに関連して、管理画面(wp-admin)だけにbasic認証をかける方法です。


ここまではと同じです。

フォルダの中の構成をこういう感じにします。

一番上の階層のindex.phpはのものから中身の変更は無いです。

次に、/wp-admin/の中。

まず、.htaccess。

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
AuthUserFile /home/サイトのパス/hoge/wp-admin/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user
order deny,allow

wp-admin/が追加になってますね。

.htpasswdは変更無いです。

次に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( dirname( __FILE__ ) . '/../../wp-blog-header.php' );

階層が一個下がるので、../を追加してあげてください。

これでwp-adminだけにbasic認証が付きますよ。
セキュアです。