Apache / 2.4.18(Ubuntu)サーバーは、.htaccessを介して特定のフォルダに対してRewriteEngineモードを使用できません。

Apache / 2.4.18(Ubuntu)サーバーは、.htaccessを介して特定のフォルダに対してRewriteEngineモードを使用できません。

私はSlimを使用してWeb APIプロジェクトを操作するときに、.htaccessルートWebの下にあるAPIフォルダを使用します。/v1私のOSはUbuntu 16.04で、このフォルダにのみ.htaccessを適用したいとApache/2.4.18思います。/v1ファイル.htaccessは次のとおりです。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

/v1フォルダ内のファイルにアクセスしようとすると404応答が表示されます。たとえば、アクセスしようとすると

http://localhost/project/v1/loadSomething

応答は404です。

Not Found
The requested URL project/v1/loadSomething was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80

次のように変更するために編集しようとしました。

<Directory "/var/www/html">
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

ただし、この場合、応答は500です。

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

ログは次のとおりです。

[Sat Aug 10 21:16:11.356667 2019] [core:alert] [pid 4699] [client 127.0.0.1:33852] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Sat Aug 10 21:20:21.783996 2019] [core:alert] [pid 4700] [client 127.0.0.1:34374] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Sat Aug 10 21:20:40.368584 2019] [core:alert] [pid 4701] [client 127.0.0.1:34376] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

誰でも私を助けることができますか?

ベストアンサー1

  1. Apache 2.4ディレクティブ以降は廃止され、新しいディレクティブに置き換えられましたOrderAllowDenyRequire通事論。

    変える

    Order allow,deny
    Allow from all
    

    そして

    Require all granted 
    

    あなたの構成から。バラよりhttps://httpd.apache.org/docs/current/upgrading.html

  2. そうだモードの書き換えあなたのサーバーではアクティブではありません。次のコマンドを使用してモジュールを有効にし(a2enmodシンボリックリンクが生成された)、サーバーを再起動します。/etc/apache2/mods-enabled/rewrite.load../mods-available/rewrite.load

    sudo a2enmod rewrite
    sudo service apache2 restart
    

    有効になっているすべてのモジュールを一覧表示するには、次のコマンドをフラグa2queryで使用できます。-m

    a2query -m
    

おすすめ記事