简体   繁体   English

Laravel基本路由错误“ NotFoundHttpException”

[英]Laravel base route errors “NotFoundHttpException”

I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException 我不是Laravel的新手...我已经写了这条路线来呼应“ Hello World”,但是它会出错NotFoundHttpException

This is my routes.php (no other code is in the file but the following): 这是我的routes.php(文件中没有其他代码,但以下内容):

Route::get('/', function(){
    return "HELLO WORLD";   
});

I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module. 我还启用了mode_rewrite,并且还在apache模块中将AlloOverride设置为'all'。

This is also the URL is use to access the page: 这也是用于访问页面的URL:

http://localhost/laravel/public/mostafa

Do: 做:

php artisan serve

Use that URL to visit your website. 使用该URL访问您的网站。

You will see that you get some output like: 您将看到一些输出,例如:

Laravel development server started on http://localhost:8000

When you have no clue what Artisan is take a look at this; 当您不知道工匠是什么时,请看一看。 http://laravel.com/docs/artisan http://laravel.com/docs/artisan

Navigate into your project directory with your command prompt and run there the serve command from above. 在命令提示符下导航到您的项目目录,然后从上方运行serve命令。

Example: 例: 在此处输入图片说明

Sometimes the default .htaccess file located in public folder doesn't work in apache. 有时,位于公共文件夹中的默认.htaccess文件在apache中不起作用。 Try altering the .htacess as mentioned here . 尝试按此处所述更改.htacess。 Alternatively renaming your laravel project folder would work especially in XAMPP. 或者,重命名您的laravel项目文件夹将特别适用于XAMPP。

Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. 其他一些框架将路径定义视为相对于项目Web根目录的路径,因此定义为/foo/bar的路径将与http://example.com/additional/levels/laravel/public/foo/bar匹配,并且即使没有更改也可以正常工作您可以将项目树移动到公共Web层次结构中的其他位置。 Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar . 但是Laravel将路由视为绝对路径,因此/foo/bar仅匹配http://example.com/foo/bar

The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/ . 最简单的解决方案可能是将代码移到单独的虚拟主机中,并将其文档根目录指向laravel/public/ (In this case it seems that's actually the intended set-up.) (在这种情况下,似乎实际上是预期的设置。)

(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.) (我想有一种方法可以使框架采用隐式前缀,但是我只使用了Laravel 10分钟。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM