すぐに忘れる「.htaccess」の備忘録
2023年08月22日
2024年02月26日
すぐに忘れる「.htaccess」の備忘録
Webサイトの制作では、頻繁に使うのに、その度に記述方法を忘れ、過去の制作案件から確認しがちな「.htaccess」の書き方の備忘録です。
URLから「index.html」を非表示
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.example.com/$1 [R=301,L]
「http」から「https」にリダイレクト
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
301リダイレクト
Redirect permanent / https://www.example.com/
基本認証
AuthUserFile "/**任意の文字列**/.htpasswd"
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
基本認証下で特定のディレクトのみを基本認証を解除
Satisfy any
order allow,deny
allow from all
ErrorDocument
ErrorDocument 404 /error/
ErrorDocument 403 /error/
ErrorDocument 500 /error/
HTMLファイルでSSIを実装
Options +Includes
AddHandler server-parsed html