Ubuntu
Apache / 2.4.18(Ubuntu)伺服器不適用於特定文件夾的.htaccess的RewriteEngine模式
當我使用 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
任何人都可以幫助我嗎?
- 自 Apache 2.4 指令以來
Order
,Allow
和Deny
被棄用並被新Require
語法取代。代替
Order allow,deny Allow from all
和
Require all granted
在你的配置中。見https://httpd.apache.org/docs/current/upgrading.html 2. 您的伺服器中似乎未啟用mod_rewrite 。使用命令啟用模組
a2enmod
(創建一個/etc/apache2/mods-enabled/rewrite.load
指向的符號連結../mods-available/rewrite.load
),然後重新啟動伺服器:sudo a2enmod rewrite sudo service apache2 restart
要列出所有啟用的模組,您可以使用
a2query
帶有-m
標誌的命令:a2query -m