Laravel:默认路由会呈现,但其他路由不会。Ubuntu/14.04 / Apache2 配置问题?不确定我做错了什么

Laravel:默认路由会呈现,但其他路由不会。Ubuntu/14.04 / Apache2 配置问题?不确定我做错了什么

Laravel 将正常呈现默认 / 根页面。但不会呈现默认路由或错误页面。当我尝试访问 /test 时,我的 Web 浏览器将返回 Apache(不是 Laravel)错误页面

以下是一些信息(如果您需要更多详细信息,请告诉我)

服务器目录树

/var/www/
└── html
    ├── access.log
    ├── app
    ├── artisan
    ├── bootstrap
    ├── composer.json
    ├── composer.lock
    ├── config
    ├── database
    ├── error.log
    ├── gulpfile.js
    ├── package.json
    ├── phpspec.yml
    ├── phpunit.xml
    ├── public
    ├── readme.md
    ├── resources
    ├── server.php
    ├── storage
    ├── tests
    └── vendor

视图(测试视图是默认欢迎视图的副本)

/var/www/html/resources/views/
├── errors
│   └── 503.blade.php
├── test.blade.php
├── vendor
└── welcome.blade.php    

航线

<?php    

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


Route::get('test', function () {
    return view('test');
});    


Route::get('anotherTest', function () {
    return 'Hello World';
});   

Apache 配置

<VirtualHost *:80>    

    # The location of our projects public directory.
    DocumentRoot    /var/www/html/public    

    # Useful logs for debug.
    CustomLog       /var/www/html/access.log common
    ErrorLog        /var/www/html/error.log    

    # Rewrites for pretty URLs, better not to rely on .htaccess.
    <Directory /www/var/html>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>    

</VirtualHost>

使用默认(提供的).htaac​​ess 文件

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>    

    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]
</IfModule>

我的错误日志也是空的,但访问日志显示 404 和 496

admini@linux:/var/www/html$ cat error.log
admini@linux:/var/www/html$ cat access.log
192.168.1.130 - - [24/Jul/2015:15:51:53 -0700] "GET / HTTP/1.1" 200 1448
192.168.1.130 - - [24/Jul/2015:15:54:46 -0700] "GET /test HTTP/1.1" 404 496
192.168.1.130 - - [24/Jul/2015:15:56:37 -0700] "GET /test HTTP/1.1" 404 496
192.168.1.130 - - [24/Jul/2015:15:57:11 -0700] "GET /test HTTP/1.1" 404 496
192.168.1.130 - - [24/Jul/2015:15:57:13 -0700] "GET /test HTTP/1.1" 404 495
192.168.1.130 - - [24/Jul/2015:16:14:53 -0700] "GET /test HTTP/1.1" 404 496
192.168.1.130 - - [24/Jul/2015:16:14:53 -0700] "GET /test HTTP/1.1" 404 495
192.168.1.130 - - [24/Jul/2015:16:18:16 -0700] "GET /test HTTP/1.1" 404 496
192.168.1.130 - - [24/Jul/2015:16:18:17 -0700] "GET /test HTTP/1.1" 404 495
admini@linux:/var/www/html$

答案1

将我的 Apache 配置文件更改为以下内容可解决问题。

<VirtualHost *:80>
    ServerName somehost
    DocumentRoot /var/www/html/public    

    CustomLog       /var/www/html/access.log common
    ErrorLog        /var/www/html/error.log    

   <Directory /var/www/html/public>
      <IfModule mod_rewrite.c>
      Options -MultiViews
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ index.php [L]
   </IfModule>
</Directory>
</VirtualHost>    

相关内容