LoginSignup
1
6

More than 3 years have passed since last update.

WordPressのログインURLを変更する方法【.htaccess】

Posted at

はじめに

WordPressのログインURLは、デフォルトでは以下のURLで共通になっていて、誰でもアクセス可能な状態になっています。

https://hogehoge.com/wp-login.php

ログインURLがわかってしまうと、アカウント名やパスワードの総当たり攻撃をするブルートフォースアタックによりログインされてしまう可能性があり、セキュリティ上の懸念があります。

セキュリティ上の問題はログインURLに誰でもアクセスできることにあるので、ログインURLを攻撃者からわからないものに変更しておけば、ブルートフォースアタックを受けるリスクは大きく軽減できます。

https://hogehoge.com/wp-login.php?xxxxxxxxxx

この記事では、WordPressのログインURLをサーバー側のファイルである.htaccessの編集によって変更する方法について紹介していきます。

WordPressのログインURLを変更する方法

サーバーのドメイン直下に置かれた.htaccessにアクセスし、以下のコードを設置してください。
レンタルサーバーなどでは、管理画面から.htaccessを編集できるようになっています。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^enter/?$ /wp-login.php?xxxxxxxxxx [R,L]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in_.*$
RewriteRule ^dashboard/?$ /wp-login.php?xxxxxxxxxx&redirect_to=/wp-admin/ [R,L]
RewriteRule ^dashboard/?$ /wp-admin/?xxxxxxxxxx [R,L]
RewriteRule ^register/?$ /wp-login.php?xxxxxxxxxx&action=register [R,L]
RewriteCond %{SCRIPT_FILENAME} !^(.*)admin-ajax\.php
RewriteCond %{HTTP_REFERER} !^(.*)hogehoge.com/wp-login\.php
RewriteCond %{HTTP_REFERER} !^(.*)hogehoge.com/wp-admin
RewriteCond %{HTTP_REFERER} !^(.*)hogehoge.com/enter
RewriteCond %{HTTP_REFERER} !^(.*)hogehoge.com/register
RewriteCond %{HTTP_REFERER} !^(.*)hogehoge.com/dashboard
RewriteCond %{QUERY_STRING} !^xxxxxxxxxx
RewriteCond %{QUERY_STRING} !^action=logout
RewriteCond %{QUERY_STRING} !^action=rp
RewriteCond %{QUERY_STRING} !^action=register
RewriteCond %{QUERY_STRING} !^action=postpass
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in_.*$
RewriteRule ^.*wp-admin/?|^.*wp-login\.php /not_found [R,L]
RewriteCond %{QUERY_STRING} ^loggedout=true
RewriteRule ^.*$ /wp-login.php?xxxxxxxxxx [R,L]
</IfModule>

上記のコードをベースに、各自の環境に応じて変更する箇所が2つあります。

1つ目は、
xxxxxxxxxxの部分を任意の文字列に変更してください。(6箇所)
https://hogehoge.com/wp-login.php?xxxxxxxxxxがWordPressのログインURLになります。

2つ目は、
hogehoge.comの部分をWordPressを設置しているドメインに応じて変更してください。(5箇所)

上記のコードにより、ログインURLは以下のURLに変更されます。

https://hogehoge.com/wp-login.php?xxxxxxxxxx

ログインURLの変更により、?xxxxxxxxxxのパラメータを知らない攻撃者がアクセスした場合は、404 Not Foundになります。

1
6
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
1
6