Reputation: 5448
On the server (shared-hosting) all the assets that are inside the public folder are not displayed. i.e.
<img src="{{asset($painting->file)}}" >
output this
<img src="http://subdir.example.com/uploads/awJ4o8_miro1.jpg" >
it supposed to have a public folder
http://subdir.example.com/public/uploads/awJ4o8_miro1.jpg
On my Public_html folder I have this folder structure
PUBLIC_HTML
├───app
├───bootstrap
├───cgi-bin
├───config
├───database
├───public
│ ├───css
│ ├───img
│ ├───js
│ ├───uploads
│ └───videos
│ .htaccess(file)
│ .index.php(file)
├───resources
├───storage
└───tests
└ .htaccess(file)
both of the .htaccess file is like this file
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>
permissions
So my questions is how can I set my configuration (.htaccess) so that I can display my assets on the shared-hosting site.
Upvotes: 1
Views: 4446
Reputation: 2807
You can prefix the asset url with public as:
{{ asset('public/' . $painting->file) }}
Upvotes: 2
Reputation: 784938
You can insert this rule just above last rule to redirect assets to 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>
Upvotes: 2