2015-07-22 202 views
1

我剛剛開始在一個新項目中使用Laravel,並且遇到了問題。將文檔根目錄設置爲public後,無法訪問公共資源

因此,我認爲我已經爲一個新項目設置了一切,並開始研究它。在我的本地機器(Windows,運行WAMP)上一切正常,我已經在個人VPS(Ubuntu,運行NGINX)上設置了它,它也工作正常。現在,我的僱主正在使用共享主機,訪問可悲的是非常有限。我有ftp訪問,他可以訪問cPanel上的一些東西。我試着直接從本地項目中使用PhpStorm部署到服務器。看起來沒問題,只有碰撞是指向文件列表,但在訪問serverlink/public時似乎沒問題。我已經要求我的僱主將文檔根目錄更改爲/ public,因此我無法訪問我的資源(css/images),這些資源是公開/公開的。生成的鏈接是它們應該是例如:serverlink/css/mycss.css,但該文件返回一個404,這很奇怪。

這裏是我的htaccess:

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

    RewriteEngine On 

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

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

在我的意見,我用刀片引用的資產,就像這樣:

<link href="{{ asset('css/button.css') }}" rel="stylesheet" type="text/css" > 

我能得到什麼試圖直接訪問瀏覽器中的文件時,是

「對不起,找不到頁面。」 1/1 NotFoundHttpException in RouteCollection.php line 145:「

任何人都可以幫我嗎?堅持這一點,尤其是因爲它在我的vps上運行良好!由於託管限制,我需要放棄Laravel 5嗎?還是可以繞過它們?

乾杯, 蒂亞戈C.

+0

'asset('css/button.css')'呈現的是什麼?什麼'url()'返回? – user2094178

+0

[.htaccess重定向除css和javascript之外的所有擴展名]的可能重複(http://stackoverflow.com/questions/15202316/htaccess-redirect-all-extension-except-css-and-javascript) – Jigar

回答

0

加入這一行的index.php

$app->bind('path.public', function() { 
    return __DIR__; 
}); 

並改變公共目錄主目錄。

0

事實證明,在根目錄下需要驗證的.htaccess存在問題。不知何故,我想當根文件夾被設置爲公開時,其他.htaccess阻止訪問文件(因爲沒有提出auth)。我因爲編輯出來,並改變了我的.htaccess(內公開)本:

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

    RewriteEngine On 
RewriteBase /public 

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

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA] 
</IfModule> 

其中也取消了「的index.php /」或在我的路線similiar的需要。

乾杯!