另一种方法是在wp配置中添加这两行。php:
define(\'WP_SITEURL\', \'http://example.com/\');
define(\'WP_HOME\', \'http://example.com/\');
然后从博客复制文件。实例com到示例。com目录并最终替换数据库中的所有URL。可以使用php脚本执行此操作:
<?php
// edit this line to add old and new terms which you want to be replaced
$search_replace = array( \'http://blog.example.com\' => \'http://example.com\');
//change the localhost,username,password and database-name according to your db
mysql_connect("localhost", "root", "rootpass") or die(mysql_error());
mysql_select_db("exampledb") or die(mysql_error());
$show_tables = mysql_query( \'SHOW TABLES\' );
while( $st_rows = mysql_fetch_row( $show_tables ) ) {
foreach( $st_rows as $cur_table ) {
$show_columns = mysql_query( \'SHOW COLUMNS FROM \' . $cur_table );
while( $cc_row = mysql_fetch_assoc( $show_columns ) ) {
$column = $cc_row[\'Field\'];
$type = $cc_row[\'Type\'];
if( strpos( $type, \'char\' ) !== false || strpos( $type, \'text\' ) !== false ) {
foreach( $search_replace as $old_string => $new_string ) {
$replace_query = \'UPDATE \' . $cur_table .
\' SET \' . $column . \' = REPLACE(\' . $column .
\', \\\'\' . $old_string . \'\\\', \\\'\' . $new_string . \'\\\')\';
mysql_query( $replace_query );
}
}
}
}
}
echo \'replaced\';
mysql_free_result( $show_columns );
mysql_free_result( $show_tables );
// mysql_close( $mysql_link );
?>
祝你好运!