Laravel 5.2: asset path not working on server

2019-09-12 00:30发布

My laravel 5.2 app unable to fetch the stylesheet from the public/css directory on the production server but can fetch stylesheets on the local machine!

here is how I am linking my files:

<link href="{{asset('css/clock.css')}}" rel="stylesheet" media="all" />

I also tried bunch of different ways:

<link href="{{URL::asset('css/clock.css')}}" rel="stylesheet" media="all" />

OR:

{{HTML::style('css/clock.css')}}

but nothing worked on server!

but it is not able to fetch the css! when I check the page source, it shows me some other css file linked.. is it because of '.htaccess' file that I used to redirect to the public folder of my site?

you can have a look at enter link description here..

please help!

3条回答
何必那么认真
2楼-- · 2019-09-12 00:56

The asset() helper prepends the base URL to the path you supply. But laravel keep js, css, and image files into public folder so you need to add public path like this:

href="public/{{ asset('css/style.css') }}.

Instead of doing this edit into this file:- vendor\laravel\framework\src\Illuminate\Foundation\helpers.php

function asset($path, $secure = null)
{
    if($_SERVER['HTTP_HOST']=='127.0.0.1:8000')
        return app('url')->asset($path, $secure);
    else
        return app('url')->asset('public/'.$path, $secure);
}
查看更多
放荡不羁爱自由
3楼-- · 2019-09-12 01:07

Why are u not trying url helper like this

<link href="{{ url('css/clock.css')}}" rel="stylesheet" media="all" />

Note:- css/clock.css is in public folder

查看更多
Animai°情兽
4楼-- · 2019-09-12 01:21
<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]

 # Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [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}]

查看更多
登录 后发表回答