0
1

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.

【Bluehost】Wordpressの管理画面だけにBasic認証がかからない!

Posted at

#事象

  • Wordpressの管理画面にBasic認証がかからない
  • 管理画面だけでなく、全体に認証がかかってしまう
  • レイアウトが崩れてしまう
  • 管理画面を表示しようとすると、Topページに飛ばされる

#原因

  • Rewiteのルールで、wp-login.phpにBasic認証をかける設定が無視されていた
    ⇒wp-login.phpのファイルのみBasic認証をかける予定が、そこに行くまでにURLが書き換えられてしまっていた。。。

#解決策
###①.htaccessの修正(ドキュメントルート配下)
下記のように修正しました。

●変更前
# BEGIN WordPress

AddHandler application/x-httpd-php5s .php

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType text/html "access plus 2 hours"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 6 hours"
</IfModule>
Header set X-Endurance-Cache-Level "2"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~tajimato/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~home/wordpress/index.php [L]
</IfModule>

# END WordPress

<Files wp-login.php>
AuthType Basic
AuthUserFile /home/test/public_html/wordpress/.htpasswd
AuthGroupFile /dev/null
AuthName "User and Password"
Require valid-user
</Files>

# END WordPress


●変更後
==================================================================================
# BEGIN WordPress

AddHandler application/x-httpd-php5s .php

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType text/html "access plus 2 hours"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 6 hours"
</IfModule>
Header set X-Endurance-Cache-Level "2"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~tajimato/wordpress/
RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f ★コメントアウト
#RewriteCond %{REQUEST_FILENAME} !-d ★コメントアウト
#RewriteRule . /~home/wordpress/index.php [L] ★コメントアウト
</IfModule>

# END WordPress

<Files wp-login.php>
AuthType Basic
AuthUserFile /home/test/public_html/wordpress/.htpasswd
AuthGroupFile /dev/null
AuthName "User and Password"
Require valid-user
</Files>

# END WordPress

###②wp-adminディレクトリに.htaccessを作成
Wordpressの管理機能が集約されたディレクトリwp-adminディレクトリに、.htaccessを作成

<Files admin-ajax.php>
Satisfy Any
Order allow,deny
Allow from all
</Files>

こちらも参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?