【问题标题】:Laravel 5.1 Route Object not foundLaravel 5.1 找不到路由对象
【发布时间】:2015-10-27 04:05:45
【问题描述】:

请帮助我,我正在使用最新版本的 xampp 开发 Laravel,不知道我的问题的原因是什么。

这条路线运行良好:

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

这条路线给出一个错误“找不到对象!”:

Route::get('about', function () {
    return 'aaa';
});

httpd.vhosts:

<VirtualHost test.loc:80>
   DocumentRoot "C:/xampp/apps/test.loc/public"
   ServerName test.loc
   <Directory "C:/xampp/apps/test.loc/public">
            #AllowOverride All - when I use this, I get a "Access forbidden!" for all routes
        Require all granted - this works for the main route, other routes give "errors".
</Directory>

/public/.htaccess:

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

【问题讨论】:

    标签: php .htaccess laravel frameworks xampp


    【解决方案1】:

    我遇到了完全相同的问题,但最后这对我有用。

    .....
    <Directory "C:/xampp/apps/test.loc/public">
       Options Indexes FollowSymLinks Includes ExecCGI
       AllowOverride All
       Require all granted
    </Directory>
    

    【讨论】:

    • AllowOverride All 解决了我在 xampp windows 上的问题
    【解决方案2】:

    将此添加到您的 httpd.vhosts 文件中

    <VirtualHost test.loc:80> 
    
     ServerName test.loc
     DocumentRoot "C:/xampp/apps/test.loc/public"
      <Directory "C:/xampp/apps/test.loc/public">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
     </Directory>
    

    【讨论】:

    • 结果是:Error 500 服务器错误!服务器遇到内部错误,无法完成您的请求。服务器过载或 CGI 脚本出错。
    • 服务器 500 错误是一个非常普遍的错误。你检查你的 PHP 错误日志了吗?
    【解决方案3】:

    您是否尝试过在名称前添加斜杠? 像这样:

    Route::get('/about', function () {
        return 'aaa';
    });
    

    【讨论】:

    • 是的,我试过了,结果是:找不到错误对象!
    • 你的 Apache 版本是多少?
    • 确保您的重写模块已激活并且您的.htaccess 正在加载。还要检查/public文件夹的权限
    猜你喜欢
    • 2017-10-29
    • 1970-01-01
    • 2015-06-26
    • 2016-06-08
    • 1970-01-01
    • 2016-11-15
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多