在 Apache 中接收 404 错误 - Cakephp 3 生产后端

Receiving 404 Error in Apache - Cakephp 3 Backend on Production

使用 Cakephp 3 路由设置路由如下

$routes->post(
    '/auth/login/*',
    ['controller' => 'WvUser', 'action' => 'login']
);

$routes->post(
    '/auth/signup/*',
    ['controller' => 'WvUser', 'action' => 'signup']
);

这在本地服务器上运行得非常好,现在我在网页上收到 404 错误。

这是 apache 的全新安装,在 /etc/apache2/apache2.conf

中稍作改动
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

尝试创建一个临时的新 Cakephp 项目,它也面临类似的问题我的项目和新的临时蛋糕骨架都有类似的 .htaccess 文件

里面/var/www/project

# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
#    RequestHeader unset Proxy
#</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^(\.well-known/.*)$  [L]
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/    [L]
</IfModule>

在 /var/www/project/webroot

里面
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

/var/www/apache2/error.log没有错误。

听起来你还没有启用 mod-rewrite in apache。

对于Ubuntu:

sudo a2enmod rewrite
sudo systemctl restart apache2

由于它的可选 (IfModule) apache 不会产生错误。

同时检查是否安装了 mb_string、intl 和 simplexml