Symfony4资产和图像未在生产环境中加载

时间:2018-12-19 12:16:14

标签: symfony mod-rewrite webpack symfony4

在Symfony4项目的prod环境中,启用webpack encore时,会出现此错误:

GET http://admin.domain.com/build/app.97d835a6.css net::ERR_ABORTED 404 (Not Found)

所引用的文件app.97d835a6.css位于/public/build文件夹中。

.htaccess是这个:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/public/.*\.(jpg|css|js|gif|png)$ [NC]
    RewriteRule ^(.*)$ public/build/$1

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png)$ [NC]
    RewriteRule ^(.*)$ /public/index.php [QSA,L]
</IfModule>

在webpack.encore.js中,这是代码:

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')
    // only needed for CDN's or sub-directory deploy
    //.setManifestKeyPrefix('build/')

它不会加载生成的资产...知道吗?

0 个答案:

没有答案