Laravel路由返回500错误

问题描述:

我将基本的Laravel项目部署到服务器。当我打开我的域时,它返回默认的欢迎视图。当我添加简单的道路(见下文)编码并尝试在浏览器中输入该路线时,它会返回500内部错误。除“/”根路由外,所有路由都返回500错误。Laravel路由返回500错误

文件夹结构:

/ 
#laravel 
#subdoms 
##api 

Laravel文件在laravel目录除了从公共目录这是在API diretory文件。在API目录

.htaccess文件:

<IfModule mod_rewrite.c> 
    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] 

    # Handle Authorization Header 
    RewriteCond %{HTTP:Authorization} . 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 
</IfModule> 

存储目录,一切都在它是可写的,可读的,可执行的人。

laravel/storage/logs中没有错误日志。

laravel /路由/ web.php:

<?php 

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

Route::get('hello', function() { // 500 internal error 
    return 'Hello world'; 
}); 

服务器信息:

服务器 - 的Linux CentOS的 - Apache 2.2的 - 服务器端包含 - SSI - PHP版本7.0.17

+0

个招呼,或者/你好? –

+0

重要吗? –

+1

是的。 “/”表示路由文件。你在那里调用了welcome.blade.php,所以你想要做的进一步调用将会在“/”之后出现。 –

解决方案1:

在所有路线之前加上'/';你的情况'/你好'。要么 ;

溶液2:

我猜的.htaccess被忽略。 http://httpd.apache.org/docs/2.2/en/mod/core.html#allowoverride

*apache2.conf file in /etc/apache2 : * 

ServerName localhost 

Mutex file:${APACHE_LOCK_DIR} default 
PidFile ${APACHE_PID_FILE} 
Timeout 300 
KeepAlive On 
MaxKeepAliveRequests 100 
KeepAliveTimeout 5 
User ${APACHE_RUN_USER} 
Group ${APACHE_RUN_GROUP} 
HostnameLookups Off 
ErrorLog ${APACHE_LOG_DIR}/error.log 
LogLevel warn 
IncludeOptional mods-enabled/*.load 
IncludeOptional mods-enabled/*.conf 
Include ports.conf 

<Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
     Require all denied 
</Directory> 

<Directory /usr/share> 
     AllowOverride None 
     Require all granted 
</Directory> 

<Directory /var/www/> 
     Options Indexes FollowSymLinks 
     AllowOverride None 
     Require all granted 
</Directory> 

选项指标了FollowSymLinks 设置AllowOverride无 要求所有授予

解决方案3:

Apache可能被配置为拒绝htaccess的覆盖。在这种情况下,您需要在VirtualHost配置中添加一个段,以允许这些段。有关更多信息,请参阅Apache文档。也可能是mod_rewrite未启用。如果使用Ubuntu,Debian或其他基于Debian的操作系统,则使用sudo a2enmod重写,然后使用sudo服务apache2重新加载即可。

这里是我的,它的工作原理

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

    RewriteEngine On 
    RewriteBase /laravel51/public/ 
    # change above to your site i.e., RewriteBase /whatever/public/ 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
</IfModule> 
+1

它没有帮助。还是一样的错误。 –

+0

@BillyRay检查编辑的答案 –

+0

它在本地主机上正常工作。当我把它放在服务器上,我必须删除: 选项-MultiViews 因为有了这个我甚至无法加载索引文件。 –