blog url redirecting

I used to host a word press blog and a forum on a server (srv71) with a domain name. And a few days ago I transferred my whole site to a new server (srv14) but I havn’t updated my dns and I’ve shutdown the former server srv71. So visiting my.domain.name/blog or my.domain.name/phpbb would lead to time out error. I tried to connect my new blog and forum using the IP address and this problem occurred.

Visiting the forum is fine (my.ip.addr.14/phpbb) but the blog would try to redirect me to my.domain.name/blog, not my.ip.addr.14/blog.

Read More

I looked into the wp-config.php and found this line:

define( 'DOMAIN_CURRENT_SITE', 'my.domain.name' );

I thought I got it and replaced ‘my.domain.name’ with ‘my.ip.addr.14’, then visiting my.ip.addr.14/blog wourd return an establishing database connection error (all the database, username, password, hostname are correct in wp-config.php, I’m certain of that).

Then I commented out this line, leaving it as default. Then again my.ip.addr.14/blog redirected me to my.domain.name/blog.

Then I backup my blog database, deleted .htaccess and wp-config.php, and reinstalled and generated new .htaccess and wp-config.php files. Now my.ip.addr.14/blog would show a empty blog with ‘hello world’, the first post by default. Then I imported the database and again my.ip.addr.14/blog redirected me to my.domain.name/blog. I checked the ‘wp_’ tables such as wp_options and wp_site but found no manually set values (all NULL) about the site url.

The newly generated .htaccess is identical to the former .htaccess file. The former wp-config.php is 8 line longer than the newly created (default) wp-config.php:

define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false);
$base = '/blog/';
define( 'DOMAIN_CURRENT_SITE', 'my.domain.name' );
define( 'PATH_CURRENT_SITE', '/blog/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Any one has dealt with similar problems? Thanks!

Related posts

1 comment

  1. Based on the code that you posted I can see you have created a Multisite installation. I’m assuming that is a mistake. I would suggest you delete you new installation, upload your old site backup and import your old database backup.

    Updating the Database

    Ok, now that things are back in place you need to update all the URLs in the database to run at the new address because WordPress uses absolute URLs. You can do this by editing the database directly through a tool like phpMyAdmin.

    This is the part where I warn everyone to backup their database first but you already have one, right?

    First and foremost, in the wp_options table you need to update siteurl and home to the new domain/IP that the site is running at. DO NOT include a trailing slash / at the end of the URLs. Something like this.

    http://123.123.123.123/blog
    

    Once that’s correct you should be able to log in.

    Now, if you intend to run the site at the new address you will want to update the remaining URLs in the database. Links to media like images and PDFs will be broken otherwise.

    There are 3 fields in 2 databases that need updating.

    wp_posts table

    • guid
    • post_content

    wp_postmeta table

    • meta_value

    Here are the MySQL queries to update those. Swap out http://www.olddomain.com and http://www.newdomain.com with your addresses.

    UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com', 'http://www.newdomain.com');
    
    UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com', 'http://www.newdomain.com');
    
    UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.com', 'http://www.newdomain.com');
    

    Finishing Details

    Your site should be pretty much ready to run at the new address. There may still be other URL entries in the wp_options table that need to be updated. This is often data used by themes and plugins.

    You can usually correct these in your theme settings, plugin settings, etc.

    You can’t update the wp_options table with the queries I posted above because often the data is serialized and those queries will break everything.

Comments are closed.