WordPressは固定ページをつくることができる。この固定ページにIPアクセス制限をかけたい。
手順
まず、アクセス制限をかけたい固定ページと同名のディレクトリを作成する。
% cd /var/www
% sudo mkdir your_eyes_only
つづいて、index.phpと.htaccessをコピーする。
% sudo cp index.php your_eyes_only/
% sudo cp .htaccess your_eyes_only/
% cd your_eyes_only
index.phpを編集する。
% sudo vi index.php
編集すべき点は以下のとおり。上のディレクトリにあるwp-blog-header.phpを参照できるように編集する。
% diff index.php ../index.php
17c17
< require( dirname( __FILE__ ) . '/../wp-blog-header.php' );
---
> require( dirname( __FILE__ ) . '/wp-blog-header.php' );
続いて、.htaccessを以下のように編集する。具体的にはアクセス制限をかける。「Require ip 192.168.11.0/24」がIPによるアクセス資源部分。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<Files "^\.(htaccess|htpasswd|htdigest)$">
Require all denied
</Files>
Require ip 192.168.11.0/24