首页 文章

Laravel 5没有找到css文件

提问于
浏览
39

我刚刚在MAMP上安装了一个Laravel 5项目,我的页面没有找到css文件 .

这是我的app.blade.php文件中我的css的链接:

<link href="/css/app.css" rel="stylesheet">

我的.htaccess文件有这一行:

RewriteBase /laravel-site/laravel-5-app/public/

在config文件夹中,我的app.php文件包含:

'url' => 'http://localhost:8888/laravel-site/laravel-5-app/public/',

但是当我打开这个页面时:http://localhost:8888/laravel-site/laravel-5-app/public/auth/login并检查开发人员工具,它正在这个位置寻找css文件:http://localhost:8888/css/app.css

正如旁注,如果我去这个网址:http://localhost:8888/laravel-site/laravel-5-app/public/我得到了正确的欢迎页面 .

11 回答

  • 3

    使用它将 cssjavascriptimages 等资产添加到刀片文件中 .

    FOR CSS,

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

    要么

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

    FOR JS,

    <script type="text/javascript" src="{{ asset('js/custom.js') }}"></script>
    

    要么

    <script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>
    

    FOR IMAGES,

    {{ asset('img/photo.jpg'); }}
    

    这是DOC

    或者,如果您拉出作为laravel 4.2默认的作曲家包 illuminate/html ,那么您可以使用如下,在laravel 5.中您必须手动拉包 .

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

    这是Example .

  • 68

    您可以使用以下选项之一:

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

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

    {!! Html::style( asset('css/app.css')) !!}
    
  • 2

    其作品 . 对于CSS:

    <link href="css/app.css" rel="stylesheet">
    

    尝试:

    <link href="public/css/app.css" rel="stylesheet">
    
  • 1

    Stop artisan serve

    并尝试使用

    php -S localhost:8000 -t public
    
  • 5

    快速应用简单的正则表达式 .

    search:href =“( . ?)”replace:href =“{{asset('$ 1')}}”

    search:src =“( . ?)”replace:src =“{{asset('$ 1')}}”

  • 2

    在根路径中创建.htaccess文件

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/public/ 
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    
    
    RewriteRule ^(.*)$ /public/$1 
    #RewriteRule ^ index.php [L]
    RewriteRule ^(/)?$ public/index.php [L] 
    </IfModule>
    

    在公共目录中创建.htaccess文件

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

    如果您在public / index.php文件中进行了任何更改,请使用正确的路径更正它们,然后您的站点将处于活动状态 .

    这将解决什么?

    • 主持laravel项目的问题 .

    • Css不适用于laravel .

    • Laravel网站无法正常工作 .

    • laravel网站加载域/ public / index.php

    • laravel项目未正确重定向

  • 3

    这是解决方案

    {!! Html::style('css/select2.min.css') !!}
      {!! Html::script('js/select2.min.js') !!}
    
  • 2

    这适合我

    如果您将.htaccess文件从公共目录迁移到项目文件夹并将server.php更改为项目文件夹中的index.php,那么这应该适合您 .

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

    谢谢

  • 1

    我遇到了同样的问题,直到现在 .

    /css/app.css 之前删除 / ,以便 css.app.css 为我工作 .

  • 6

    我的意见是:

    <link rel="stylesheet" href="{{ URL::to('/css/app.css') }}">
    

    是路由到您的CSS文件的最佳方法 .

    URL ::也适用于js

  • 4

    我用了:

    "{{asset('css/custom.css')}}"
    "{{asset('css/app.css') }}"
    

    第一个是我自己的文件,第二个是laravel . 我正在使用第5版 .

    http://spanibox.com/css/app.css有效,但http://spanibox.com/css/custom.css没有 . 我觉得这很奇怪 .

相关问题