更新时间:2022-01-18 21:25:42
Laravel 中的 NotFoundHttpException
异常总是意味着它无法为 特定网址.在您的情况下,这可能是您的 Web 服务器配置、虚拟主机(站点)配置或 .htaccess 配置中的问题.
A NotFoundHttpException
exception in Laravel always means that it was not able to find a router for a particular URL. And in your case this is probably a problem in your web server configuration, virtual host (site) configuratio, or .htaccess configuration.
您的 public/.htaccess 应该如下所示:
Your public/.htaccess should look like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
如你所见,第一行IfModule mod_rewrite.c
中有一个条件,所以如果你没有安装或启用mode_rewrite,所有的重写规则都会失败,这个
As you can see there is a condition in the first line IfModule mod_rewrite.c
, so if you don`t have mode_rewrite installed or enabled, all rewrite rules will fail and this
localhost/Test/public/
可以正常工作,但不是这样:
Will work fine, but not this:
localhost/Test/public/test
另一方面,这个也应该可以工作,因为这是它的原始形式:
In other hand, this one should work too, because this is its raw form:
localhost/Test/public/index.php/test
因为 Laravel 需要重写它才能工作.
Because Laravel needs it to be rewritten to work.
请注意,您不应使用/public,您的网址应如下所示:
And note that you should not be using /public, your URLs should look like this:
localhost/Test/
这是您的虚拟主机的文档根目录未正确配置或未指向/var/www/Test/public 或您的应用程序所在的任何路径的另一个线索.
This is another clue that your virtual host's document root is not properly configured or not pointing to /var/www/Test/public, or whatever path your application is in.
所有这一切都假设您使用的是 Apache 2.
All this assuming you are using Apache 2.