内容纲要
一. 当网站的域名发生变更时,通过数据库语句调整域名为新的域名
- 进入mysql
#进入docker docker exec -it mysql-5.7 sh #进入mysql命令行 mysql -u wordpress -ppassword
- 修改数据库记录
-- 查看网站属性设置 -- 找到 siteurl 和home记录 select * from wp_options where option_name in ('siteurl','home'); +-----------+-------------+----------------------+----------+ | option_id | option_name | option_value | autoload | +-----------+-------------+----------------------+----------+ | 1 | siteurl | https://abc.com/ | yes | | 2 | home | https://abc.com/ | yes | +-----------+-------------+----------------------+----------+ -- 更新记录为新的域名 update wp_options set option_value ='https://123.com/' where option_id=2; update wp_options set option_value ='https://123.com/' where option_id=1;
二. 修改wordpress设置,是系统自动获取当前域名.这种修改的方法,其实并不真正改为“相对路径”,而是通过判断域名,将域名付给home和siteurl两个全局变量,这样访问路径会随访问域名改变,很适合网站迁移时使用。
修改wp-config.php,在wp-config.php的最后加上以下语句:$home = 'http://'.$_SERVER['HTTP_HOST']; $siteurl = 'http://'.$_SERVER['HTTP_HOST']; define('WP_HOME', $home); define('WP_SITEURL', $siteurl);