最近不知为何,电信的线路西南地区这边访问国外网站超慢(得到众多网友的证实),很多论坛和博客上不去,我自己的博客也如此,想更新一篇文章都更新不了。用过了代理,用了翻墙工具都不行。相当郁闷,我给电信打电话,他问我是不是访问违法网站。。。算了。。。当我没问。。
国内的GFW实在太过强大,考虑再三,我决定还是让博客回国,理由:
①电信时不时用GFW限制一下这,禁止一下那。。。这样折腾我的博客必然劳命伤残,总有一天会挂!
②我博客上的内容大多是关于技术与互联网的舆论,与政治无关。被和谐的几率是很小的。
③速度,我所用的site5主机的速度还是可以的,只是比国内慢那么一点点,全世界任何一个地方的网民访问都很快,但是我博客本身也是中文博客,群体是中国人,所以放国内速度应该快点,起码用电信的用户肯定是很快!
综上几条,所以觉得回国也是挺好的,虽然国内环境严峻点!多长个心眼呗!哈哈
刚刚接到twitter上消息,部分人反映访问国外网站速度又上来了。。。。不过我还是老样,不管咋滴,回国是定了,不能再这样折腾下去了!
现在就正式开始转移的全过程,自所以我标题上“全攻略”因为我这次转移碰到的问题太多,最后一一解决,所以应该这篇文章能解决大部分网友转移过程中出现的问题!
1:转移前的准备工作,
①.数据库备份。这里要注意的是你的mysql版本,现在的mysql大多分为4.0和5.1俩个版本,所以如果你以前的版本和现在要转移的版本不同,那就需要转换,或者你让你们的服务商给你换myslq版本也可以!如果实在不能转换的话,就用 帝国备份王 这个web程序去进行备份,具体的备份方法这里不再讲了,可以参阅说明,很详细的。实在不清楚你让服务商的工程师给你转换,一般都肯!(备份的时候尽量用zip或者gzip方式导出!)
②备份网站文件。这个很简单,就是把所有的博客文件都下载下来,如果您的控制面板有在线压缩功能那相当方便。
2:开始转移。
①把数据库导入到你mysql数据库里。
②把网站文件上传到FTP空间。
③修改wp-config.php配置文件,配置文件如下:
根据上面的说明更改一下你的配置文件就完成了一小半了!
现在应该基本可以访问你的网站。
3.相关后续更改!WordPress在windows主机上会出现如下几个问题:
①不支持伪静态。很多小公司的windows主机不支持伪静态,如果你的空间不支持伪静态,那么就无法使用自己自定义的url地址访问博客文章,你可以要求服务商为你添加组件,否则后面也不用看了!
②即使支持伪静态,但是windows主机的伪静态地址在域名后多了一个“index.php/”,比如我以前的文章地址是“http://www.ctovip.com/archives/702”,但是现在非得用“http://www.ctovip.com/index.php/archives/702”才能访问,这样会影响你的seo,别人无法通过以前搜索引擎的收录条目,访问到你的网站!这样网站的流量大大下降!
解决这个问题的方法有俩种:
1.404方法:这个方法很简单,只要你的空间支持404错误页面自定义指向即可。创建一个404的错误页面,命名404.php(当然其他的也可以,可以随意取名!)
然后在里面输入如下代码:
然后就把404错误指向这个文件,最后就到wp后台更改你自己希望的链接地址,就当这是一个liunx主机,就行了!(注意那个"../index.php"这个路径!)
2.rewriter组件方法:这个方案很麻烦,而且需要有isapi操作权限,如果你不嫌麻烦,当然也可以使用这个。
下载wp-rewrite组件,在IIS的Isapi上添加筛选器,筛选器名称为Rewrite,可执行文件选择Rewrite.dll,重新启动IIS.然后修改wp-rewrite目录下的httpd.ini配置文件,修改里面的规则,以实现伪静态,我这里有一个规则是写好的,默认支持三种格式的伪静态!
规则如下:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# # WordPress rewrite rules#
# # Below is for permalink like /post/%post_id%.html
# # Provided By Sideblue
# # URL:http://www.xbaohe.com
RewriteRule /post/tag/(.*) /index.php?tag=$1
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(contact|about-copyright|favor|archives|tags|sitemap) /index.php?pagename=$1
RewriteRule /post/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2
RewriteRule /post/category/?(.*) /index.php?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index.php?author_name=$1
RewriteRule /rss.xml /wp-feed.php/?feed=rss2
RewriteRule /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
# RewriteRule /([0-9]+)/?([0-9]+)?/?$ /index.php?p=$1&page=$2
# RewriteRule /post/([0-9]+)/?([0-9]+)?/?$ /index.php?p=$1&page=$2
RewriteRule /post/([0-9]+).html /index.php?p=$1
RewriteRule /page/(.*)/?s=(.*) /index.php?s=$2&paged=$1
RewriteRule /page/(.*) /index.php?paged=$1
RewriteRule /post/date/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /post/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /post/date/([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /post/([0-9]+).html/(feed|rdf|rss|rss2|atom) /index.php?feed=rss2&p=$1
RewriteRule /post/([0-9]+).html/trackback /wp-trackback.php?p=$1
# # Below is for permalink like /%year%/%monthnum%/%day%/%postname%.html
# # Maybe dumplicate with above!!
# # Provided By Sideblue
# # URL:http://www.xbaohe.com
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(contact|about-copyright|favor|archives|tags|sitemap)/ /index.php?pagename=$1
RewriteRule /category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2
RewriteRule /category/?(.*) /index.php?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index.php?author_name=$1
RewriteRule /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
RewriteRule /page/(.*)/ /index.php?paged=$1
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?([0-9]+)?.html/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+).html/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+).html/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4&tb=1
# # Below is for permalink like /%year%/%monthnum%/%day%/%postname%/
# # Maybe dumplicate with above!!
# # Provided By Sideblue
# # URL:http://www.xbaohe.com
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(contact|about-copyright|favor|archives|tags|sitemap)/ /index.php?pagename=$1
RewriteRule /category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2
RewriteRule /category/?(.*)/ /index.php?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index.php?author_name=$1
RewriteRule /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
RewriteRule /page/(.*)/ /index.php?paged=$1
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4&tb=1
# # Below is For Discuz!
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteCond Host: (.+)
RewriteCond Referer: (?!http://1.*).*
RewriteRule .*.(?:gif|jpg|png) /block.gif
这个规则可以实现如下三种伪静态!
/post/%post_id%.html
/%year%/%monthnum%/%day%/%postname%/
/%year%/%monthnum%/%day%/%postname%.html
你可以用其中任何一种伪静态格式,填到你们的wp后台去即可!
如果你的WordPress博客是放在windows虚拟空间的根目录下,那么到这里基本已经完成了!但是如果你想把WordPress放到windows空间的一个子目录下运行,那么可以继续往下看!
③把WordPress放到子目录并且让访问地址仍然是根地址!比如我的博客放在我空间的/cto子目录下,但是现在我们访问的时候并没有在地址里面看到任何cto路径,是不是!本来应该是通过 "http://www.ctoren.com/blog/"这个地址访问我的博客,但是我们现在仍然能用"http://www.ctovip.com/" 来访问! 现在你看的这篇文章真实的地址应该是:"http://www.ctoren.com/blog/archives/751",但是现在是通过"http://www.ctovip.com/archives/751"访问! 这个特性估计也只有WordPress有,这个也是WordPress官方给出的方法,方法很简单:
1、新建一个用来存放WordPress核心文件的新文件夹(例如我的 /cto目录)。
2、进入选项(options)面板。
3、找到WordPress address (URL)(中文用户请查找”WordPress 地址(URL)“)这个选项:把后面的地址改成你存放WordPress文件的文件夹地址。比如:http://www.ctovip.com/cto
4、找到Blog address (URL)(中文用户请查找”Blog 地址(URL)“)这个选项:把此地址改为你网站的根目录的URL。例如:http://www.ctovip.com
5、点击Update Options(中文用户为”更新设置“)。
6、把WordPress的核心文件转移到你新建的文件夹中,也就是cto 这个目录。
7、把index.php和.htaccess文件从cto目录转移到根目录中。
8、用文本编辑器打开并编辑根目录下”index.php”这个文件。
9、找到如下代码,修改并保存:找到
require(’./wp-blog-header.php’);
把地址改为你WordPress目录下的文件:
require(’./cto/wp-blog-header.php’);
10、登陆控制面板,新的控制面板地址为http://www.ctoren.com/blog/wp-admin/
11、打开永久链接选 项面板更新Permalinks结构。如果.htaccess有正确的权限设置的话WordPress会自动更新你的.htaccess文件。如果 WordPress不能写入你的.htaccess文件,就会显示新的rewrite规则,因此你就需要手动把rewrite规则复制 到.htaccess文件中.
现在更换了目录了,那么相应的刚才我们设置的404错误页面代码里面的"index.php"文件的路径也要做相应更改,改成"../index.php"。
到这里基本你的网站能正常打开访问,但是你会发现,以前你上传到网站上的图片,都无法显示,这是因为以前你图片的地址是在网站跟目录,现在都到/cto目录去了。
所以还剩最后一步,就是更改mysql数据库里面的图片路径!(说到这里觉得WordPress居然不支持相对路径,非得用绝对路径,这一点相当麻烦,对于更换域名,或者更改网站地址目录,这些操作,就太麻烦了!)
进入phpmyadmin执行sql语句批量替换!
update wp_lansh_posts set post_content=replace(post_content,'http://www.ctovip.com/wp-content/uploads','http://www.ctoren.com/blog/wp-content/uploads')
这里的 wp_lansh_posts 是我WordPress里面的文件表,post_content是图片的连接地址字段,'http://www.ctoren.com/blog/wp-content/uploads'是以前的图片路径地址,'http://www.ctoren.com/blog/wp-content/uploads'是我更改目录后的地址,大家可以按照这个语法随便去替换!好了,执行后刷新一下页面,一切就跟你在liunx主机上的WordPress一摸一样了。而且是放在子目录的!
这篇文章写的非常详细,应该能帮很多朋友转移到windows主机解决问题,
也是整理一下自己的思路,希望自己以后如果再做转移的时候能够更清楚问题!
是不是看的有点迷糊,呵呵,写的多了。。。可以多看几篇就清楚了。。。如有疑问,欢迎留言!
原创文章,如需转载,请标明出处:http://www.ctovip.com/archives/751 lansh频道




@yang
….欢迎光临
@lansh
sadfafsd
@久酷
呵呵 是快点。不过是win主机,如果是liunx的效率会搞点!
放到国内速度是快了不少啊,呵
@yinheli
你在本地调试没有 永久链接?
你是直接IIS? 我看到网上的虚拟机的WordPress都有这个现象。通病!
@lansh
我有空拿你的这个办法在本机搭建一个看看…
事实上我本机(默认永久链接情况下)测试是没有问题的.我看看你的这个伪静态.试试.
@yinheli
我暂时停用了。。。。。好东西不能用。不知道其他插件有问题没。
@lansh
这个很奇怪.我就不知道了.它是通过POST方式传递了个参数.用来判断不加载一部分信息的.NT下不能用的情况让我困惑.
仔细看了.我先收藏.以后也许用的上.
@yinheli
哈哈 我正要跟你说 你的首页分页ajax插件,在windows主机上不能使!
配置都没改动。。。不能用了!。。你看看!
沙发党~