Laravel5 路由问题 /home页面无法访问
都已接安装完成。 http://localhost/laravel/public/ 可以正常访问。
但是http://localhost/laravel/public/home 无法访问。提示Not Found
The requested URL /laravel/public/home was not found on this server.
home 路由系统自带的啊
1, routes.php 路由
Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
2,HomeController.php home 控制页面
<?php namespace App\Http\Controllers;
class HomeController extends Controller {
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
return view('home');
}
}
3, home.blade home视图
<html>
<head>
<title>Laravel</title>
<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
color: #B0BEC5;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
margin-bottom: 40px;
}
.quote {
font-size: 24px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<p>lishuai 你好! 少壮不努力老大徒伤悲!!</p>
</div>
</div>
</body>
</html>
我想让http://localhost/laravel/public/home 显示出 home 视图来。
但是http://localhost/laravel/public/home 无法访问。提示Not Found
The requested URL /laravel/public/home was not found on this server.
home 路由系统自带的啊
1, routes.php 路由
Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
2,HomeController.php home 控制页面
<?php namespace App\Http\Controllers;
class HomeController extends Controller {
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
return view('home');
}
}
3, home.blade home视图
<html>
<head>
<title>Laravel</title>
<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
color: #B0BEC5;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
margin-bottom: 40px;
}
.quote {
font-size: 24px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<p>lishuai 你好! 少壮不努力老大徒伤悲!!</p>
</div>
</div>
</body>
</html>
我想让http://localhost/laravel/public/home 显示出 home 视图来。
9 个回复
fen995
赞同来自: 王二麻子
我应该解决了 吧
原来我以为http://localhost/laravel/public/home 这样访问。
现在才知道是http://localhost/laravel/public/index.php/home 这样访问 。
可以 了
谢谢bobby 、Mr_Jing 。
Mr_Jing
赞同来自:
fen995
赞同来自:
bobby
赞同来自:
LoadModule rewrite_module modules/mod_rewrite.so前面的#去掉看看
我原先也是卡在这里好几天,差点弃坑
现在也是刚刚跨过这个坎
fen995
赞同来自:
不管怎么说的谢谢你。 我再找找什么问题
健儿
赞同来自:
Route::get('photo', 'PhotoController@index');
控制器PhotoController 下默认的index方法 这样访问死活访问不到 按照楼主说的那样倒着访问 ,把路由写在最后就可以了,但我觉得好奇怪 有点违背常理,明天问问同事去
冰刀
赞同来自:
aravel_test.dev/public/home
Route::get('/home', 'HomeController@tindex');
nginx :
location / {
try_files $uri $uri/ /index.php?$query_string;
}
我这么写的怎么还是报错: file not found 啊?
雾里看花
赞同来自:
CKT小凌
赞同来自:
开启apache模块
在apache配置文件
LoadModule rewrite_module modules/mod_rewrite.so前面的#去掉
然后添加
/usr/local/apache2/htdocs/ 为网站目录,我是linux的
<Directory /usr/local/apache2/htdocs/>AllowOverride all
Options Indexes FollowSymLinks
Require all granted
</Directory>
到apache配置文件,随便放,为了好找我放在最下名