1
2

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.

XServer で テスト環境のみBASIC認証をかける方法

Posted at

はじめに

サブドメインのディレクトリ内に「.htaccess」を置いて、そこにBASIC認証の記述をするのが最も簡単です。
ですが、私は親元のディレクトリにだけ「.htaccess」を置きたい宗派の人間ですので、方法を記載します。

前提

ドキュメントルートの構成が次の通りであること
(XServerでサブドメインを作成したら自動でディレクトリができるはずです)

本番環境 ドキュメントルート

/home/{{ サーバID }}/{{ ドメイン名 }}/public_html/

例: www.hogehoge.jp の場合 => /home/hogehoge/hogehoge.jp/public_html/

テスト環境 ドキュメントルート

/home/{{ サーバID }}/{{ ドメイン名 }}/public_html/{{ サブドメイン名 }}

例: test.hogehoge.jp の場合 => /home/hogehoge/hogehoge.jp/public_html/test/

.htaccess にこれを書く

/home/hogehoge/hogehoge.jp/public_html/.htaccess
AuthUserFile /home/hogehoge/hogehoge.jp/htpasswd/.htpasswd
AuthType BASIC
AuthName "Basic Auth"
Require valid-user

Satisfy Any
SetEnvIf Host "^www.hogehoge.jp$" no_auth

Order Deny,Allow
Deny from all
Allow from env=no_auth
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?