Apache - 404 未找到

Apache - 404 Not Found

下午好,

我正在详细说明一个项目,我已经在 ubuntu16.04 的 virtualbox 中安装了 php、mysql、apache2。我在本地工作并且安装了 laravel 5.3,我有一个 API 运行 并创建了一个新的虚拟主机并放置了 DocumentRoot my_folder/publicServerName name_virtual_host。然后我转到我的主机文件并放置了一个新行:127.0.0.1 name_virtual_host。当我在浏览器上放置 http://name_virtual_host, the laravel page appears like it is supposed, but when I type in http://name_virtual_host/api 时,它返回:

Not Found

The requested URL /api was not found on this server.

Apache/2.4.18 (Ubuntu) Server at name_virtual_host Port 80 it used to appear JSON.

我的虚拟主机:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName name_virtual_host
        DocumentRoot /var/www/my_folder/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

如果在我的文件夹中,我写命令

php artisan serve

并输入 URL:

name_virtual_host:8000/api

,这有效。

我该如何解决这个问题? 我认为解决方案是创建文件 .htaccess,但是我应该在这个文件 (.htaccess) 中放入什么?

谢谢。

Laravel should come with a public/.htaccess file 将所有请求重定向到 index.phpRewriteRule ^ index.php [L] 部分)。

如果您没有此文件,请添加它。如果您已经拥有此文件,请确保在您的 Apache 服务器上启用了 mod_rewrite(并重新启动它)。

如果没有它,Apache 将在您请求 /api 时在您的 DocumentRoot 中查找名为 api 的文件。请求必须从 laravel documentation:

发送到 index.php

The public directory contains the index.php file, which is the entry point for all requests entering your application.