cancel
Showing results for 
Search instead for 
Did you mean: 

https page cannot find js and css files after install SSL certifcate

Highlighted

https page cannot find js and css files after install SSL certifcate

I'm using CEv2.2.2 and run on ubuntu 16.04 with apache2 server. I have set up a live site without ssl certificate and it is working fine. But then after I installed SSL certificate, the https:// page is all messed up.

See here:

http://www.sostransfer.com/index.php/

and in comparison:

https://www.sostransfer.com/index.php/

 

I have already tried: 

bin/magento setup:upgrade

bin/magento setup:static-content:deploy -f

bin/magento cache:flush

bin/magento cache:clean

 

I have tried checking the file permissions, but can't find anything wrong (or I may have lost my mind not knowing what to look for).

 

If I do the SSLEngine rewrite to force http to redirect to https, everything broke. So I removed that from .htaccess. So I can access the page both with http and https, and only http works.

 

What gives? Thanks for any help!

 

6 REPLIES 6
Highlighted

Re: https page cannot find js and css files after install SSL certifcate

Hello @sdssrr 

 

First check in admin that you've setup base URL for both http and https correctly and for media as well.

run below commands :

 

rm -rf pub/static/frontend/* pub/static/adminhtml/* var/cache/ generated/* var/page_cache/ var/view_preprocessed/ var/composer_home 
php bin/magento setup:static-content:deploy
php bin/magento c:f

Note : don't use -f while deploying static content if your site is in production mode.

 

if these solution doesn't work, get help from this answer:

https://community.magento.com/t5/Magento-2-x-Technical-Issues/JS-amp-amp-CSS-not-loading-After-Enabl...

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !
Highlighted

Re: https page cannot find js and css files after install SSL certifcate

No still doesn't work.

 

In admin panel, base url section,

base url and base link url are both http://www.sostransfer.com/

base urls (Secure) section,

secure base url and secure base link url are https://www.sostransfer.com/

No url for static view files or media files are set.

 

I have found the following behaviour, anything with https: cannot be found, while clearly the file exists via http get. For example,

GET
https://www.sostransfer.com/pub/static/version1597031231/frontend/Magento/luma/en_US/mage/calendar.css

returns 404 Not Found

But

GET
http://www.sostransfer.com/pub/static/version1597031231/frontend/Magento/luma/en_US/mage/calendar.css

returns 200 OK

 

Highlighted

Re: https page cannot find js and css files after install SSL certifcate

@sdssrr 

 

Make sure you have in system configuration --> web --> secure urls to allow ssl in front end.

and your base url(s) have a '/' in ending.

 

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !
Highlighted

Re: https page cannot find js and css files after install SSL certifcate

yes all URL's have '/' at end.

 

In admin panel setting "Use Secure URLs on Storefront" to "yes". Does not make any difference.

 

Highlighted

Re: https page cannot find js and css files after install SSL certifcate

The problem is server can't find the file via https request while it serves the file for http request. What would cause a server to not finding the file when requested through https? It's the same file, located in the same directory. Is there some configuration problem with my ssl installation?

 

Here's how I installed it. I just added the following in the apache conf file:

<VirtualHost {my_ip}:443>
ServerAdmin webmaster@localhost
DocumentRoot {path_to_my_public_html}
ServerName www.sostransfer.com
ServerAlias sostransfer.com
ErrorLog {path_to_logs/error.log}
SSLEngine on
SSLCertificateFile {path_to_sostransfer.com_ssl_certificate.cer}
SSLCertificateKeyFile {path_to_.sostransfer.com_private_key.key}
SSLCertificateChainFile {path_to_.sostransfer.com_ssl_certificate_INTERMEDIATE.cer}
</VirtualHost>

 

Check with apache conf tool and all fine. IP and paths all correct.

 

I noticed the Virtualhost:80 section has some extra directives:

<Directory {path_to_public_html}>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

 

Do I need to include these in 443 section as well?

 

Highlighted

Re: https page cannot find js and css files after install SSL certifcate

Oh my god, I think I just answered my own question.

Added the missing directives in the Virtualhost:443 section and it worked! I think it's because it didn't use .htaccess in the magento folders if the apache conf directive is not set to use them.