Help us understand the problem. What is going on with this article?

.htaccessのメモ

More than 5 years have passed since last update.

.htaccessのメモ

IP制限

ディレクトリ自体に設定(指定したIPのみ可)

# 優先順位
Order deny,allow
# すべて禁止
deny from all
# 指定したIPのみ許可
allow from 123.123.123.123
allow from 234.234.234.234

ファイルごと設定(指定したIPのみ可)

<Files example.html>
Order deny,allow
deny from all
allow from 123.123.123.123
allow from 234.234.234.234
</Files>

リダイレクト

# 開始
RewriteEngine On

指定ページにリダイレクト

# 指定ページを除く
RewriteCond %{REQUEST_URI} !examle.html
# ループ防止
RewriteCond %{REQUEST_URI} !ex_error.html
# スマホ制御
RewriteCond %{HTTP_USER_AGENT} ! (iPhone|Android.*Mobile|Windows.*Phone)
# エラーページへ遷移
RewriteRule ^(.*)$ html/ex_error.html [R]
RewriteBase /

httpsにリダイレクト

# 必ずhttpsにリダイレクト
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

引越し

みそは301で永久引越し

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ http://www.abc.123.jp/page/ [R=301,L]
Redirect 301 / http://www.abc.456.jp/page/

ベーシック認証

.htaccessの記述

AuthUserFile /var/www/example.com/.htpasswd
AuthGroupFile /dev/null
AuthName "Input ID and Password."
AuthType Basic
require valid-user
<Files ~ "^.(htpasswd|htaccess)$">
deny from all
</Files>

.htpasswdの記述

example:ibWEPMMsR.AJc
ユーザー名:hash化したパスワード

参考URL:htpasswd作成

http://www.luft.co.jp/cgi/htpasswd.php

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away