昰道 發表於 2023-10-6 00:00:00

为wordpress绑定多个域名的方法分享

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我们都知道,wordpress默认情况下会自动跳转到后台规定的home_url上去,例如你的空间同时绑定了jb51.net和www.jb51.net,你使用带www的作为网站的访问地址,那么当别人访问的jb51.net的时候,wordpress会自动将其跳转到www.jb51.net。同样的道理,如果你绑定了其他的域名,即使不会出现这个跳转,但你的网站内的链接都会带上www.jb51.net,这是由于wordpress内部的home_url,site_url,image_url等机制决定的,例如你的主题中使用了wordpress菜单功能,那么这些菜单中的链接是一定会带上www.jb51.net的。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
由于上述的先天基因,我们不能像其他网站系统一样,试图为网站绑定多个域名。不过wordpress社区中有一些牛人,他们为我们提供了解决方案。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
其中一种最简洁的方法:在你的wp-config.php中添加如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode2" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);<br>
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
即可完成多域名的绑定。理解起来也很简单,通过对WP_SITEURL和WP_HOME的重新定义,当你使用一个域名去访问它时,wordpress内部的机制就会将需要用到访问地址的地方全部修改为当前访问的域名。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
但这种方法过于暴力,对搜索引擎是不友好的,因为这种方法仅仅是让网站可以被多域名访问,可是,这会给搜索引擎带来识别上的困难,一般会认为是镜像网站,从而直接对能访问到的所有网站进行打压,甚至K掉所有域名。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
为了挽回一些局面,有人提出了可以适当修改一些元素,例如不同的域名使用不同的网站标题,对网站内部的一些核心词汇进行替换。于是,有人开始在这方面进行研究,并最终开发出了三个有用的插件:<br>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
Multiple Domains with Analytics<br>
MultiDomain<br>
Domain Mirror</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
但实际上,现代搜索引擎非常智能,单单修改网站标题,恐怕也于事无补。不过我们实际上可以对wordpress进行深入开发,在此基础上可以让wordpress焕发新的生机,以此为基础,我们可以为wordpress的不同栏目、不同作者绑定不同的域名,当然,这是需要有无数的作者和内容的支持才可行的。</p>
頁: [1]
查看完整版本: 为wordpress绑定多个域名的方法分享