【问题标题】:CSS files in Laravel 5.1 not accessible, not foundLaravel 5.1 中的 CSS 文件无法访问,未找到
【发布时间】:2015-12-14 15:08:23
【问题描述】:

我正在尝试在我的页面中包含一个 css 文件。我已经在我的刀片模板中做到了这一点:

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

然后我的css文件在{laravel_root}/public/css/frontend.css

结果页面输出

<link rel="stylesheet" href="http://hbnw.app/css/frontend.css">

但是使用 chrome 的开发工具,我看到服务器根据请求返回 200 OK 响应,但文件为空。

我在宅基地环境中运行。我是否需要对 Laravel 5 的路线做点什么,还是有完全不同的 CSS 工作流程?我可以更改 htaccess 以返回所有以 /css 和 /js 开头的请求的文件吗?

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

提前致谢。

【问题讨论】:

  • 文件是空的还是找不到?

标签: php css .htaccess laravel-5.1


【解决方案1】:

我不确定出了什么问题,但它现在可以正常工作了。我很抱歉。

【讨论】:

    【解决方案2】:

    Laravel 不处理公用文件夹中的文件。 Laravel 附带的.htaccess 仅在请求与公共目录中的现有文件或文件夹不匹配时通过 Laravel 路由(index.php)发送请求。

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 1970-01-01
      • 2016-01-19
      • 2015-11-16
      • 2016-01-14
      • 2015-08-28
      • 1970-01-01
      • 2014-08-04
      • 2022-01-04
      相关资源
      最近更新 更多