Magento 2找不到CSS和JS文件 [英] Magento 2 can't find css and js files

查看:618
本文介绍了Magento 2找不到CSS和JS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前感谢您的帮助!

我将基于Magento 2的网站从托管转移到了本地主机. 我清除了缓存,在core_config中调整了(安全和不安全)URL,使用cli运行静态内容deploy().检查了所有允许的文件夹".

I moved my site based on Magento 2 from hosting to my localhost. I cleared cache, adjusted(secure and unsecure) urls in core_config, run static content deploy() using cli. Checked all permitions for "folder".

Magento运行,但没有CSS和JS文件.

Magento runs but with no css and js files.

在控制台中,我可以看到以下内容:

In console I can see the following:

请提供一些建议,我应该怎么做才能解决此问题? 预先感谢!

Please give some advice, what should I do to remove this issue? Thanks in advance!

P.S: 赢10 打开服务器(PHP7x64,MySQL5、7x64,Apache-PHP7-x64 + Nginx1.10) 没有外部缓存

P.S: Win 10 Open Sever (PHP7x64, MySQL5,7x64, Apache-PHP7-x64+Nginx1.10) No external caching

P.P.S在从主机复制站点之前,我尝试使用cli使用示例数据设置magento,并且遇到了同样的问题!因此,我相信这不仅是将magento 2从主机迁移到本地的问题. 我可以看到M2尝试从pub/static中不存在的version1485628564文件夹中加载所有文件

P.P.S Before I copied site from host I tried to setup magento with sample data using cli and I received the same issue! So I believe it's not only issue about moving magento 2 from host to local. I can see that M2 tries to load all files from version1485628564 folder which doesn't exist in pub/static

http://magehost.two/pub/static/**version1485628564**/frontend/Magento/luma/en_US/mage/calendar.css

推荐答案

您需要更新/pub/static文件夹下的.htaccess文件.打开MAGENTO_DIR/pub/static/.htaccess并添加以下代码:

You need to update the .htaccess file under /pub/static folder. Open MAGENTO_DIR/pub/static/.htaccess and add the following code:

...
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /pub/static/ # <- Add This
...

或者,您可以通过使用以下查询将此记录添加到core_config_data表中来禁用静态文件签名:

Alternatively, you can disable static file signing by adding this record into the core_config_data table with this query:

INSERT INTO `core_config_data` VALUES (NULL, 'default', 0, 'dev/static/sign', 0);

在这种情况下,请记住,执行查询后必须刷新缓存.

In this case, keep in mind that you have to flush the cache after executing the query.

这篇关于Magento 2找不到CSS和JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆