帮助中心 >  技术知识库 >  网站相关 >  网站运营 >  WordPress模板如何使用SSL(https)外链

WordPress模板如何使用SSL(https)外链

2017-02-10 14:33:29 12468

方法1:使用wordPress HTTPS插件解决外链问题。

(1)wordpress后台下载名称为“wordpress https(SSL)”的插件;

blob.png

(2)启用https插件,然后测试https访问;

blob.png

方法2:修改wordpress配置文件解决外链问题。

(1)修改wordpress配置文件,添加以下几行代码:

$home = 'http://'.$_SERVER['HTTP_HOST'];

$siteurl = 'http://'.$_SERVER['HTTP_HOST'];

define('WP_HOME', $home);

define('WP_SITEURL', $siteurl);

修改后如下:

blob.png

(2)修改数据库ssl_options表中siteurl和home的option_value值均为:“/”。

blob.png

(3)修改wp-includes/post.php文件,修改函数wp_get_attachment_url为如下代码:

function wp_get_attachment_url( $post_id = 0 ) {

  $file_dir=dirname(__FILE__);

   $server_root=$_SERVER[DOCUMENT_ROOT];

   $file_dir=substr($file_dir,strlen($server_root));

   $file_dir=substr($file_dir,0,-12);

   if($file_dir!=''){

       $file_dir='/'.substr($file_dir,1);

   }

   $post_id = (int) $post_id;

   if ( !$post =& get_post( $post_id ) )

       return false;

   $url = '';

   if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) {

   //Get attached file

       if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {

       //Get upload directory

           if ( 0 === strpos($file, $uploads['basedir']) )

           //Check that the upload base exists in the file location

               //$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);

               //replace file location with url location

               $url=$file_dir.'/wp-content/uploads/'.$file;

           elseif ( false !== strpos($file, 'wp-content/uploads') )

               //$url=$uploads['baseurl'].substr($file,strpos($file, 'wp-content/uploads') + 18 );

               $url=$file_dir.'/wp-content/uploads/'.$file;

           else

               //$url = $uploads['baseurl'] . "/$file";

               //Its a newly uploaded file, therefor $file is relative to the basedir.

               $url=$file_dir.'/wp-content/uploads/'.$file;

       }

   }

   if ( empty($url) )

   //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this.

       $url = get_the_guid( $post->ID );

   if ( 'attachment' != $post->post_type || empty($url) )

       return false;

   return apply_filters( 'wp_get_attachment_url', $url, $post->ID );

}

(4)登录wordpress后台,确认多媒体中图片的链接为相对路径; 

(5)并在已经使用这些资源的文章、主题页面图片中重新插入此图片,或修改为与多媒体中图片一致的相对路径;

         外观中重新添加图片或修改为相对的图片路径;

(6)排查其他地方是否有使用多媒体资源,按照以上方法调整即可。


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: