Apache2.4でhtaccessが使えないときに確認する方法
Webサーバーを作成する上で、避けて通れないのがhtaccessの問題です。え?これは動いているの?とか、htaccessが有効になっているか確認するのも難しいです。
有効になっているかの確認
VPSなどでは、モジュールがロードされているか確認してくださいと検索するとでてきますが、そんなもんロードされている可能性は高いです。 [c] LoadModule rewrite_module modules/mod_rewrite.so [/c] ↑これは /etc/httpd/conf.modules.d/00-base.conf の中にあってロードされています。yumでインストールされている場合なら尚更されています。
有効になっているのに、動いているかわからない
問題はこっちです。モジュールがロードされているけど動かないんですよね。正確には動いているかわからないんです。
有効になっているか確認する方法
以下のコードを書いてドキュメントルートに置きます(ここではデフォルトの/var/www/htmlとします)
[c] AuthType Basic AuthName hoge Require valid-user [/c] 本当はAuthUserFileなんかも必要だけど、ダイアログ出すのが目的なのでここではいらない。 Apache/.htaccessが使えるか確認する - Googloid
- リンク先が無くなっていたのでリンクを削除しました
これでダイアログがでたり、500エラーなどになれば有効です。何もなければ無効です
無効の場合はconfファイルを確認
おそらく、デフォルトだと無効の場合が多いかもしれません。僕はConohaのLAMPパッケージ(CentOS7/Apache2.4系)でしたが、ダイアログはでませんでした。
confファイルを修正
というわけでconfファイルを修正します。該当箇所は131行目付近です [c] <Directory "/var/www/html">
Possible values for the Options directive are "None", "All",
or any combination of:
Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
Note that "MultiViews" must be named *explicitly* --- "Options All"
doesn't give it to you.
The Options directive is both complicated and important. Please see
http://httpd.apache.org/docs/2.4/mod/core.html#options
for more information.
Options FollowSymLinks
AllowOverride controls what directives may be placed in .htaccess files.
It can be "All", "None", or any combination of the keywords:
Options FileInfo AuthConfig Limit
AllowOverride None ←Allに変える
Controls who can get stuff from this server.
Require all granted [/c] です。AllowOverride NoneをAllowOverride Allに変更してapacheの再起動をします。 [c] systemctl restart httpd [/c] これで再度ダイアログがでるか確認します。でたらhtaccessは有効になってます。
