15

我是 Lavarel 框架的初学者。我知道 MVC 结构,因为我之前在 ASP.net 中使用过它,但是使用 Laravel 让我很困惑。

我已经使用以下目录在目录中安装了 Laravel photozoom

composer create-project laravel/laravel photozoom --prefer-dist

这是我的app/routes.php

<?php

Route::get('/', function()
{
    return View::make('hello');
});

Route::get('users', function()
{
    return 'users route is working!';
});

当我运行时http://localhost/photozoom/public/users,我得到404 Not Found错误。

但是当我尝试时http://localhost/photozoom/public/,会调用路由/并调用相应的视图。

我什至尝试为users路线创建一个视图。使用 Laravel 文档。我创建了两个文件:

layout.blade.php

<html>
    <head>
        <title>Laravel Quickstart</title>
    </head>
    <body>
        <h1>Laravel Quickstart</h1>

        @yield('content')
    </body>
</html>

users.blade.php

@extends('layout')

@section('content')
    Users!!!
@stop

但是,当我打电话时,http://localhost/photozoom/public/users我得到了404 Not Found error

这是我的public/.htaccess文件:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

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

我正在使用 PHP 5.5、Apache 2.4.6 。

任何帮助,将不胜感激。


已解决 启用 mod_rewrite 后,我也必须启用AllowOverride

4

4 回答 4

24

暂时试试http://localhost/photozoom/public/index.php/users。然后启用漂亮的 URL

于 2013-08-28T15:17:14.760 回答
7

/public 目录中的 .htaccess 文件启用漂亮的 URL。为了让 .htaccess 文件完成它的工作:

  • Apache2 必须启用 mod_rewrite (a2enmod rewrite)
  • 在您的 Apache 配置中,您必须使用 AllowOverride 选项以允许 .htaccess 文件“覆盖”您的默认 Apache2 配置。

例如:

<Directory /var/www/photozoom/> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
于 2014-02-23T21:22:10.607 回答
0

There are two AllowOverride in the httpd.conf file.

<Directory />
    AllowOverride All
    Require all denied
</Directory>

and

DocumentRoot "D:/www"
<Directory "D:/www">
    AllowOverride All
    Require all granted
</Directory>
于 2015-01-31T02:14:54.877 回答
0

如果您正在运行 Windows 10,那么您只需要做一件足够简单的事情。

在 c:/wamp64/www/ 中创建新文件夹并从 laravel 文件夹中复制所有文件并粘贴到您刚刚创建的文件夹中,这就是我的解决方案。

于 2017-01-11T07:59:18.767 回答