22

After upgrade from the Magento 2.1.0 to the Magento 2.1.3 (using composer) static content is not loading anymore. In the browser console I can see that all files is unavailable (404):

files unavailable preview

I don't see directories with the name version* in the pub directory.

What I already made but it didn't help:

  1. set all permissions to 777, but without success.
  2. cleaned cache
  3. removed the pub/static/*
  4. regenerated static content few times
  5. replaced the .htaccess file (in the pub/static directory) with the file from an official repository.

Another info:

  • mod_rewrite is enabled
  • FollowSymLinks is allowed (in the default host configuration and local .htaccess)
  • This configuration worked fine with Magento 2.1.0 before the updating to the 2.1.3
  • pub/static is writable

Any suggestions?

  • Did you redeploy static content? – Eamonn Dec 15 '16 at 9:01
  • Yes, I did it many times without success – Siarhey Uchukhlebau Dec 15 '16 at 9:03
  • I'm having the same issue, upvoted. In my case I'm using Nginx and the same conf files. Updating was done using composer, and did the same steps as @SiarheyUchukhlebau did – Kevin Chavez Dec 15 '16 at 15:30
  • Oh dear. Suddenly got the same problem, but using Apache. Clearing pub/static set it off and I can't seem to fix it. – Eamonn Dec 16 '16 at 11:30
  • May have found a solution below. – Eamonn Dec 16 '16 at 11:45
26

The main issue was caused by the incorrect rewrites work ( as @Marius told ). There was no RewriteBase in my directory pub/static/ and Apache could not find the files because searched for them from the root folder. After we’ve added: RewriteBase /pub/static everything start working.

How it worked:

by this address:

http://m2.uchuhlebov.web.ra/pub/static/version1481885888/frontend/Magento/luma/en_US/mage/requirejs/mixins.js

the rewrite should work:

RewriteRule ^version.+?/(.+)$ $1 [L]

as the line started from the root folder:

/pub/static/version...

it hasn’t worked and could not redirect to the file, needed.

Rewrite without base:

rewrite doesnt work

Rewrite with base:

rewrite works

Here a part of my .htaccess file from the pub/static (rewrites) :

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /pub/static
    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* ../static.php?resource=$0 [L]
</IfModule>

How to disable static-files versioning:

If you do not want to use static files versioning you can disable this feature in the Magento admin area:

config

It is possible to change this setting for default scope using the following MySQL query:

INSERT INTO `core_config_data`(`path`, `value`) VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE `value`=0

Then execute next command to clear a configuration cache:

bin/magento cache:clean config

PS: My answer is actual for the apache2 users. If you are using NGINX see this answer (by @kevin-javitz)

  • if dev/static/sign in exists then insert it. INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/static/sign', '0') – Dhaduk Mitesh Jun 20 '18 at 7:13
  • On apache2 systems, you need to enable mod_rewrite with:- sudo a2enmod rewrite. – Dallas Clarke Jan 21 at 8:14
8

If you are running Nginx, here is the fix. You probably have your own conf file, you need to update the /static/ part with this, they have updated part of it specifically: # Remove signature of the static files that is used to overcome the browser cache section:

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
        rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}
  • Additional note, if you are using apache make sure you have this in your pub/static/.htaccess line 16: RewriteRule ^version.+?/(.+)$ $1 [L] – Kevin Chavez Dec 15 '16 at 16:26
  • Thank you for your reply, it pointed me to the correct solution of the issue. I use Apache and the solution is different, but i’m grateful to you anyway. – Siarhey Uchukhlebau Dec 16 '16 at 11:18
  • You are a life safer! I was banging mu head against the wall! Can confirm it work for my nginx Magento 2.1.3 – Cudos Dec 17 '16 at 11:34
5

Go to the database and insert a row in core_config_data table:

INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/static/sign', '0');
4

There shouldn't be a version* folder in the static folder.
This most probably happens because you don't have mod_rewrite enabled in your instance.
The path pub/static/version1234/some/asset.js should be rewritten to pub/static/some/asset.js. The version thing is there only for browser cache expiration.

  • I check mod_rewrite and it is enabled: [root@web www]# httpd -M | grep "rewrite" rewrite_module (shared) Syntax OK in the .htaacess it is enabled too – Siarhey Uchukhlebau Dec 15 '16 at 9:29
  • make sure that FollowSymLinks is allowed. This happened to me after installing the latest version from github and I had a problem with the mod_rewrite and with the FollowSymLinks. – Marius Dec 15 '16 at 9:30
  • In the rewrite section FollowSymLinks is set as Options +FollowSymLinks and there was no problem with the same configuration before up-dating :( – Siarhey Uchukhlebau Dec 15 '16 at 9:38
4

It seems like the 2.1.3 release assumes the default value for Stores => Configuration => Developer => Static Files Settings => Sign Static Files is set to Yes.

So instead of changing the rewrites, its possible to set this feature to No.

If it's not possible to do this from the admin, because the admin fails to load the frontend assets, change/add this setting in the core_config_data table:

scope: default
scope_id: 0
path: dev/static/sign
value: 0

This issue is also noted on Github: https://github.com/magento/magento2/issues/7869

2

If you're using apache. You mustn't delete the .htaccess from pub/static. You can get a replacement here.

  • Thank you. I have already replaced that file, but issue was in the incorrect RewriteBase. – Siarhey Uchukhlebau Dec 16 '16 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.