我第一次尝试使用 Laravel 5.1。我能够安装它并且https://sub.example.com/laravel/public/
正在显示应该显示的内容。但是,我创建的视图给出了 404 错误“找不到页面”。
这是我到目前为止所做的:
我创建了一个控制器laravel\app\Http\controllers\Authors.php
这是背后的代码Authors.php
file
<?php
class Authors_Controller extends Base_Controller {
public $restful = true;
public function get_index() {
return View::make('authors.index')
->with('title', 'Authors and Books')
->with('authors', Author::order_by('name')->get());
}
}
然后我创建了一个视图laravel\resources\views\Authors\index.blade.php
这是背后的代码index.blade.php
file
@layout('layouts.default')
@section('content')
Hello, this is a test
@endsection
然后我创建了一个布局laravel\resources\views\layouts\default.blade.php
这是背后的代码default.blade.php
file
<!DOCTYPE html>
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
@if(Session::has('message'))
<p style="color: green;">{{ Session::get('message') }}</p>
@endif
@yield('content')
Hello - My first test
</body>
</html>
最后我创建了一条路线laravel\app\Http\routes.php
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('authors', array('as'=>'authors', 'uses'=>'authors@index'));
但由于某种原因,我不断收到 404 错误“找不到页面”。
我通过取消注释该行在 Apache 2.4.9 上启用了 mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
然后重新启动阿帕奇。
据我所知php_info()
输出 mod_rewrite 已启用
Loaded Modules
core mod_win32 mpm_winnt http_core mod_so mod_php5 mod_access_compat mod_actions mod_alias mod_allowmethods mod_asis mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_rewrite mod_setenvif mod_socache_shmcb mod_ssl
我当前的 .htaccess 文件看起来像这样“这是出厂默认值”
选项-多视图
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
我还尝试将其更改为下面的代码文档:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
但是,当我访问时,我仍然收到 404 页面
https://sub.example.com/laravel/public/authors
我究竟做错了什么?
我该如何解决这个问题?