Static Content Loading issue when Upgrade From Magento 2.1.0 to Magento 2.1.3



Reason:-

There was no RewriteBase in directory pub/static/ and Apache could not find the files because searched for them from the root folder. After it added: RewriteBase /pub/static everything start working. 

Solution 1:-
The rewrite should work:

RewriteRule ^version.+?/(.+)$ $1 [L]
add above line in .htaccess file (pub/static).your .htaccess file should look like this.
If you are running apache change in .htaccess file (pub/static)

<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>

 Solution 2:-

Magento 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.

Solution 3:-
Change sign static files to Yes from 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

or run this query

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


you can check this issue here https://github.com/magento/magento2/issues/7869,
Solution :-  
If you are running Nginx then update server config file with this

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";
}






Comments

Popular posts from this blog

Product export duplicate rows for product in Magento 2.1.2 or 2.1.x

How to debug Magento