wordpress更换服务器,和朋友公用一个数据库,遇到一些问题:
- wordpress表前缀替换
- url重写配置
- 插件启用以及调试
1.wordpress 更改前缀
Blog更换服务器,用了一空间。无奈有多个Wordpress,只有更换表的前缀。
wordpress默认wp_为前缀,以下更改数据库前缀教程只需要在phpmyadmin运行十几个sql命令即可,傻瓜式的。
首先做的就是更改十个表的前缀,这个简单,命令如下:
ALTER TABLE wp_comments RENAME TO [prefix]_comments
ALTER TABLE wp_options RENAME TO [prefix]_options
ALTER TABLE wp_posts RENAME TO [prefix]_posts
ALTER TABLE wp_postmeta RENAME TO [prefix]_postmeta
ALTER TABLE wp_users RENAME TO [prefix]_users
ALTER TABLE wp_usermeta RENAME TO [prefix]_usermeta
ALTER TABLE wp_links RENAME TO [prefix]_links
ALTER TABLE wp_terms RENAME TO [prefix]_terms
ALTER TABLE wp_term_taxonomy RENAME TO [prefix]_term_taxonomy
ALTER TABLE wp_term_relationships RENAME TO [prefix]_term_relationships
上面的命令就是将默认的前缀wp更改为[prefix],如果你想更改前缀了,只需要替换[prefix],然后需要在wp-config.php中找到
$table_prefix = ‘wp_’;
将它替换为
$table_prefix = ‘[prefix]_’;
这样后台会登陆不上去,更改options表中项wp_user_roles,以及usermeta以下三项:
- wp_autosave_draft_ids
- wp_capabilities
- wp_user_level
这四项中autosave_draft_ids是日志自动保存,user_roles和user_level是权限方面的,那个capabilities搞不懂是什么,但直觉告诉我也需要修改,所以继续在sql下运行以下命令:
update [prefix]_options set option_name = replace(option_name,'wp_user_roles','[prefix]_user_roles')
update [prefix]_usermeta set meta_key = replace(meta_key,'wp_capabilities','[prefix]_capabilities')
update [prefix]_usermeta set meta_key = replace(meta_key,'wp_user_level','[prefix]_user_level')
update [prefix]_usermeta set meta_key = replace(meta_key,'wp_autosave_draft_ids','dianso_autosave_draft_ids')
这样,我们的目的也达到了,我可以保证,使用此方法可以100%保证对数据库没什么伤害,尽量不要使用编辑器等工具直接替换wp_,因为有些数据库中插件名,绝对地址,文章中都可能存在wp_这个关键词.
It works!插件也正常:)
2.url重写配置
- wordpress/feed返回404
- wordpress/feed/rss返回404
- 404 Error After Moving WordPress to another server
- WordPress Feed 404 Error After Movind WordPress to another server
Apache:打开Apache的URLRewrite模块,如果用的是空间,在空间的设置里将重写打开。
IIS:给IIS装上ISAPI Rewrite,不了解?没问题,看看ISAPI Rewrite 介绍及相关应用就明白了。我的http.ini文件写法:
Apche:turn you apche URL_Rewrite Mod on, otherwise you are using space, turn it on in your control panel or you can tell your hosting server client.
IIS: install ISAPI_Rewrite in your IIS. and my http.ini file is below:
RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /(contact|about|contact|photo|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})/([^/]+)/?$ /index\.php\?name=$3
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
3.插件部分:
遇到问题的插件有download monitor,数据全部被清零,方法论的思想研究发现:
windows 服务器换到linux服务器,linux对大小写敏感,在Download Monitor插件里面查找:
- DLM_DOWNLOADS
- DLM_CATS
- DLM_FORMATS
- DLM_STATS
- DLM_LOG
- DLM_META
替换为:
- dlm_downloads
- dlm_cats
- dlm_formats
- dlm_stats
- dlm_log
- dlm_meta
替换过程中注意大小写。
或者将数据库中[*]_dlm_[*]全部修改为大写的。