0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Wordpress】『.htaccess ファイルの有効化が必要なオプションですが、ファイルが書き込み可能ではありません。』警告の解決方法

0
Posted at

エラー概要

WordpressのReally Simple SSLに以下の警告が表示されていました。

  <IfModule mod_rewrite.c>                                                        
  RewriteEngine on RewriteCond %{HTTPS} !=on [NC] RewriteCond %{REQUEST_URI}      
  !^/\.well-known/acme-challenge/ RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1      
  [R=301,L] </IfModule>\  

.htaccessは以下の通り。

.htaccess
  <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  </IfModule>

  <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on [NC]
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  </IfModule>

  Options -Indexes

  php_value upload_max_filesize 200M
  php_value post_max_size 400M
  php_value memory_limit 256M
  php_value max_execution_time 30000
  php_value max_input_time 30000         

3年前にも同じ警告があって、上記のように書いたのですが、どうやら今回はそれでは足りないよ、というメッセージらしい。

原因

HTTPSリダイレクトのルールがWordPressのルールの後にあるため、先にWordPressのルールが処理されている?と思い、以下のように書き直しました。

.htaccess
  <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on [NC]
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  </IfModule>

  <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  </IfModule>

  Options -Indexes

  php_value upload_max_filesize 200M
  php_value post_max_size 400M
  php_value memory_limit 256M
  php_value max_execution_time 30000
  php_value max_input_time 30000         

しかし、警告メッセージは消えず。

所有者や権限に問題がある可能性もあるらしいので、早速確認。

-rw-r--r-- 1 root root

ここに問題があったようです。

.htaccessの所有者がrootになっています。
このサーバではApacheを使っているのですが、通常www-dataapacheユーザーで動作するため、644だと書き込めません。

解決方法

ということで、以下のように実行。

  # Apacheのユーザーを確認
  ps aux | grep apache

  # 所有者を変更(Ubuntu/Debianの場合)
  sudo chown www-data:www-data .htaccess  
  sudo chmod 644 .htaccess

原因は、www-dataユーザー(Apache)が書き込めなかったこと、にありました。

以上!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?