2
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 3 years have passed since last update.

httpd.confのSetEnvはDirecotiryごとに設定できる

Last updated at Posted at 2021-03-19

ググっても情報が見つからなかったので調べました。
同じような人の助けになれば。

こんな感じでhttpd.confの Directory 内で SetEnv を使って環境変数を設定します。

httpd.conf
<VirtualHost *:80>
  DocumentRoot /var/www/sample.jp/
  ServerName sample.jp.internal

  <Directory "/var/www/sample.jp/aaaaa">
    SetEnv TEST_ENV aaaaa
  </Directory>
  <Directory "/var/www/sample.jp/aaaaa/bbbbb/ccccc">
    SetEnv TEST_ENV ccccc
  </Directory>
</VirtualHost>

で下記のPHPを各階層に置いて出力を見てみます。

echo_env.php
<?php
echo $_SERVER['TEST_ENV'];

結果は以下の通りです。
/aaaaa/bbbbb/ccccc/aaaaa にそれぞれ.htaccessを置いてSetEnvする場合と同じ挙動となりました。

https://sample.jp.internal/aaaaa/echo_env.php
# aaaaa

https://sample.jp.internal/aaaaa/bbbbb/echo_env.php
# aaaaa

https://sample.jp.internal/aaaaa/ccccc/echo_env.php
# ccccc

https://sample.jp.internal/aaaaa/ddddd/echo_env.php
# aaaaa
2
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
2
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?