Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

After the website opens https, the picture is still http by default

Under normal circumstances, webmasters or companies that have requirements on the website will generally enable https. Secured http is a more secure form of website. However, if there is a small picture on the site that does not use http, there will be no small lock.

Web Tier Configuration SSL

Security Lock-Brand-SEO-Public Opinion-Optimization-米国生活
However, in the web layer, if https SSL has been configured through Apache, etc., see the article on how to add an https security lock and search on this site: How to add a security lock to a website https.

Application layer configuration SSL

Then the second step, you can check the Application application layer.
Configuration-Brand-SEO-Public Opinion-Optimization-米国生活
No matter what kind of CMS you use, there should be a location for the default website URL, so configuring it here will basically solve this problem.

Data Layer Configuration SSL-History Picture

Of course, this can only solve the newly uploaded pictures in the future, so how to deal with historical pictures?
Either through the function, modify it in the Application layer, or modify it directly in the database through SQL.
Application layer:
Add the following code in function.php (applicable to the two cases where the old and new domain names are inconsistent/consistent)

  1. /* Replace the image link with https */
  2. /* Source Pinellia stack */
  3. function https_image_replacer($ content){
  4. if( is_ssl() ){
  5. /*It has been verified that the data can also be obtained using $_SERVER['SERVER_NAME'], but it seems that $_SERVER['HTTP_HOST'] is better*/
  6. $host_name = $ _SERVER['HTTP_HOST'];
  7. $http_host_name='http://'.$host_name.'/wp-content/uploads';
  8. $https_host_name='https://'.$host_name.'/wp-content/uploads';
  9. $ content = str_replace($http_host_name$https_host_name$ content);
  10. }
  11. return $ content;
  12. }
  13. add_filter('the_content', 'https_image_replacer');

Simplified (provided the domain name is not modified):

  1. function replacehttp($ content){
  2. if( is_ssl() ){
  3. $ content = str_replace('http://Domain/wp-content/uploads', 'https://domain/wp-content/uploads', $content);
  4. }
  5. return $ content;
  6. }
  7. add_filter('the_content', 'replacehttp');

Database data layer:

  1. PDATE wp_posts SET post_content = replace(post_content, 'http://domain/wp-content/uploads','https://domain/wp-content/uploads');
Back to Top