10
8

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.

RewriteEngine On にならない場合は、mod_rewrite を有効にする

Last updated at Posted at 2019-09-04

未だに、Apache2のRewriteEngine はオプションなので、有効にしてあげないと動作しない。

error.log
/var/www/html/folder/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

現在の状態を確認する

apache2 のモジュール関連が有効かどうかは、 /etc/apache2/mods-enabled を見れば分かる。

# ls /etc/apache2/mods-enabled
access_compat.load  auth_basic.load  authz_core.load  autoindex.conf  deflate.load  env.load	 mime.load	   negotiation.conf  reqtimeout.conf  setenvif.conf  status.load
alias.conf	    authn_core.load  authz_host.load  autoindex.load  dir.conf	    filter.load  mpm_prefork.conf  negotiation.load  reqtimeout.load  setenvif.load
alias.load	    authn_file.load  authz_user.load  deflate.conf    dir.load	    mime.conf	 mpm_prefork.load  php7.load	status.conf

mod_rewrite を有効にする

# a2enmod rewrite

apache2 を再起動する

service apache2 restart

(番外) Dockerfile でやる場合は

以下の行を Dockerfile に追加しておけばOK。

Dockerfile.
RUN a2enmod rewrite \
  && service apache2 restart
10
8
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
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?