javascript - Can not get css and js files in the server that use SSL

808

I have implemented a website in codeigniter , recently I upload it to the production server that has SSL on it.

The problem is , if I enter using "http", everything works fine. If I enter using "https" , then all css and js is not found. And the error is :

Mixed Content: The page at 'https://www.xxxx.com/' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://www.xxxx.com/secure/validate_credentials'. This endpoint should be made available over a secure connection.

Mixed Content: The page at 'https://www.xxxx.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://www.xxxx.com/assets/font-awesome/css/font-awesome.css'. This request has been blocked; the content must be served over HTTPS.

I have already edit the config.php in codeigniter

e.g. $config['base_url'] = "https://www.xxxx.com/"

but still happen, how to debug and fix it? Thanks for helping

41

Answer

Solution:

You have everything in you error message:

This request has been blocked; the content must be served over HTTPS.

It looks like you have static link in your html to 'http'. So instead of using protocol directly in your html like that:

http://www.xxxx.com/assets/font-awesome/css/font-awesome.css

Change it to something like this:

assets/font-awesome/css/font-awesome.css

Also remember that if you are trying to use JS or CSS from other domains that are not configured to serve content with https you will encounter this issue.

552

Answer

Solution:

Like maque said You have everything in you error message

But it is recommended to usebase_url() instead ofsite_url for resources and like css, js and images.

you may upgrade to Codeigniter 3.0it is still in develop in the time of writing this answer but it is very solid at this stage and it has better version ofbase_url() andsite_url() as you can now add the protocol in the argument like that

site_url("assets/js/jquery.min.js", "https")

People are also looking for solutions to the problem: How to replace dot with comma in price format in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.