WordPress在安装的时候会默认绑定当前的域名,但是在后面再绑定其他域名的时候发现页面的链接还是安装时候的域名,今天WordPress主题站就为大家分享一下WordPress绑定多个域名的教程。

1. 打开网站根目录下的 wp-config.php,在 define(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_DEBUG\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, false);后面添加下面内容:

define(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_SITEURL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

define(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_HOME\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

这两句的意思就是设置网站域名为当前访问的域名,也就是取消了域名的绑定,如果不需要任意域名都能访问,只是几个域名的话,可以这样:

$domain = array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”www.a.com\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”www.b.com\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”www.c.com\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”);

if(in_array($_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’], $domain)){

define(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_SITEURL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

define(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_HOME\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

}

把指定的域名放在$domain 数组里面即可。

注意:

如果是 https,请修改代码里面的 http://为 https://;

如果网站安装在二级目录,则将\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]修改为\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’http://\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . $_SERVER[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’HTTP_HOST\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’].\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/对应目录名\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’

2. 在完成上面的工作以后,你的网站已经可以实现多域名访问了,但是还是有一个问题,那就是静态资源,在 wordpress 上传的图片插入文章里面,地址是固定的,修改域名以后,并不会修改图片的域名,所以还需要修改静态文件地址,使用以下代码可以解决:

define( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’WP_CONTENT_URL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/wp-content\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

把这段代码加入上面的代码下面即可。

OK,到这里你的网站已经完美的突破了域名绑定的限制了。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部