htaccessの備忘録

noimage

WPサイトにベーシック認証

AuthUserfile /home/r1234/html/sample.com/wp/.htpasswd
AuthGroupfile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user

AuthUserfileはユーザーのIDとパスワードを書いた「.htpasswd」のある場所を記述します。
AuthNameはパスワードを入力するときに表示されるテキスト。
Authtype認証方式の指定。basic認証を使うのでbasicと記述。
require valid-user認証されたユーザーは全員アクセスを許可するという意味。

WPのログイン画面にベーシック認証

<Files wp-login.php>
AuthType Basic
AuthUserFile /home/r1234/html/sample.com/wp/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
require valid-user
</Files>

<Files wp-login.php>で、「wp-login.php」にアクセス制限。

メンテナンス画面にリダイレクト

ErrorDocument 503 /mente.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/mente.html
RewriteCond %{REMOTE_ADDR} !=123.456.789.000
RewriteRule ^.*$ - [R=503,L]
</IfModule>

【サイト全体】httpをhttpsにリダイレクト

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

末尾「/index.html」を末尾「/」にリダイレクト

RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://example.com/$1 [R=301,L]
RETURN
top