0

在服務器(共享主機)內的所有資產屬於公共文件夾內不顯示的資產。即laravel:如何顯示的公用文件夾

<img src="{{asset($painting->file)}}" > 

輸出這個

<img src="http://subdir.example.com/uploads/awJ4o8_miro1.jpg" > 

它應該有一個公共文件夾

http://subdir.example.com/public/uploads/awJ4o8_miro1.jpg 

在我的public_html文件夾我有這樣的文件夾結構

PUBLIC_HTML 
├───app 
├───bootstrap 
├───cgi-bin 
├───config 
├───database 
├───public 
│ ├───css 
│ ├───img 
│ ├───js 
│ ├───uploads 
│ └───videos 
│ .htaccess(file) 
│ .index.php(file) 
├───resources 
├───storage 
└───tests 
└ .htaccess(file) 

兩個的.htaccess文件的是這樣的文件

DirectoryIndex public/index.php 
<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^public/index.php [L] 
</IfModule> 

權限

enter image description here

所以我的問題是我如何可以設置我的配置(的.htaccess),這樣我可以顯示我的共享託管網站上的資產。

+0

生成的URL是正確的,你的' public'文件夾是你的文件根目錄,不應該包含在URL中。你使用'/ public'來訪問你的網站嗎? – Jerodev

+0

喜@Jeredov。沒有我不使用'/公共區域/'接取我的網頁,但如果我改變**網址**和**添加**公衆把它一切正常'http://miro.mongexweb.ca/public/uploads/ NUsZlC__MG_5032.jpg' –

回答

0

您可以將這個規則只是最後一條規則上面資產重定向到public/

DirectoryIndex public/index.php 
<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] 

    RewriteRule ^uploads(/|$) /public%{REQUEST_URI} [L,NC,R=301,NE] 

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

你可以用公共前綴資產網址:

{{ asset('public/' . $painting->file) }} 
相關問題