如何解决Laravel 5.1 - 404没有发现? [英] How can I fix Laravel 5.1 - 404 Not Found?

查看:1824
本文介绍了如何解决Laravel 5.1 - 404没有发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Laravel 5.1首次。我能够安装和 https://sub.example.com/laravel/public/ 显示的是什么是应该的。然而,我的看法是创建给我一个404错误页面没有找到。

I am trying to use Laravel 5.1 for the first time. I was able to install it and https://sub.example.com/laravel/public/ is displaying what is should. However, views I create are giving me a 404 error Page not found.

这是我迄今所做的:

我创建了 laravel \\程序\\的Http控制器\\ \\控制器Authors.php

下面的背后是code中的 Authors.php 文件

Here is the code behind the 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视图\\意见\\作者\\ index.blade.php

下面的背后是code中的 index.blade.php 文件

Here is the code behind the index.blade.php file

@layout('layouts.default')


@section('content')
    Hello, this is a test
@endsection

然后我在 laravel创建布局\\资源\\意见\\布局\\ default.blade.php

下面的背后是code中的 default.blade.php 文件

Here is the code behind the 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 \\程序\\ HTTP \\ routes.php文件

<?php
Route::get('/', function () {
    return view('welcome');
});

Route::get('authors', array('as'=>'authors', 'uses'=>'authors@index'));

但由于某些原因,我不断收到找不到的404错误页面。

But for some reason I keep getting 404 error Page not found.

我通过取消注释出该行启用mod_rewrite的在我的Apache 2.4.9

I enabled the mod_rewrite on my Apache 2.4.9 by uncommenting out the line

LoadModule rewrite_module modules/mod_rewrite.so

然后重新启动Apache的。

Then restarted Apache.

从我可以在 php_info()输出mod_rewrite的启用告诉

From what I can tell in the php_info() output the mod_rewrite is enabled

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文件看起来像这样,这是出厂默认

My current .htaccess file looks like this "which is the factory default"


    
        选项​​-MultiViews
    

Options -MultiViews

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]

我也试图将其更改为code如下,[文档 1

I have also tried to change it to the code below as per the [documentation1

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

不过,我仍然得到404页,当我去到

However, I am still getting the 404 page when I go to

https://sub.example.com/laravel/public/authors

我是什么做错了吗?
我怎样才能解决这个问题?

What am I doing wrong? How can I fix this problem?

推荐答案

我看到的是能够访问/路线,但所有其他网页返回404相同的行为,当我第一次安装Laravel网站。

I see the same behaviour of being able to visit the / route but all other pages return a 404 when I first setup Laravel sites.

在Apache配置文件httpd.conf或的httpd-vhosts.conf您需要启用可以放置在.htaccess文件中的指令。

In your apache config file httpd.conf or httpd-vhosts.conf you need to enable the directives that can be placed in the .htaccess file.

下面是我虚拟主机配置的例子:

Here is an example of my VirtualHost configuration:

<VirtualHost *:80>
    ServerAdmin admin@gmail.com
    DocumentRoot "C:/www/laravel_authority-controller_app/public"
    ServerName authoritycontroller.www
    ErrorLog "logs/AuthorityController.www-error.log"
    CustomLog "logs/AuthorityController.www-access.log" common
    <Directory "C:/www/laravel_authority-controller_app/public">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    </Directory>
</VirtualHost>

有关您的问题的关键项是的AllowOverride全部。这应该是足以让该网站的工作,但你也可以包括选项要求所有批准,如果他们对面是一致的整个网站。

The key entry for your issue is AllowOverride All. This should be enough to get the website working but you can also include options and Require all granted if they are consistent across the entire website.

这篇关于如何解决Laravel 5.1 - 404没有发现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆