2017-06-12 147 views
0

我將基本的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

解決方案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 因爲有了這個我甚至無法加載索引文件。 –