当我使用 Slim 处理 Web API 项目时,我使用根 web 下的.htaccess
API 文件夹。/v1
我的操作系统是 Ubuntu 16.04,带有Apache/2.4.18
.我只想为该/v1
文件夹应用 .htaccess 。该.htaccess
文件如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
当我尝试访问/v1
文件夹中的文件时,我收到404
响应。例如,如果尝试访问
响应将是 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
自 Apache 2.4 指令
Order
、Allow
和开始Deny
,已弃用并被新指令取代Require
句法。代替
Order allow,deny Allow from all
和
Require all granted
在你的配置中。看https://httpd.apache.org/docs/current/upgrading.html
它似乎模组重写您的服务器中未启用。使用以下命令启用模块(这会创建指向的
a2enmod
符号链接),然后重新启动服务器:/etc/apache2/mods-enabled/rewrite.load
../mods-available/rewrite.load
sudo a2enmod rewrite sudo service apache2 restart
要列出所有启用的模块,您可以使用
a2query
带有-m
标志的命令:a2query -m