Migrating to a Different Domain

Each install of WordPress is pretty much stuck to the domain name you gave it at the start. However, I wanted to try out my theme on my own development server before moving it over to the main site. It didn’t help that the .htaccess rules made it impossible to run both sites in parallel.

Since all the references to the site URL should be in the database, I figured that if I exported the existing database to an SQL file then did a find and replace before importing it into the new database, everything should be fine.

Using phpmyadmin, I exported the existing database, then used the replace function in gedit to replace all instances of the site URL with the new one. Note that there are a couple of ways in which this is used. Most instances have the full URL (https://domain.com/subfolder), but there are a couple of entries where the domain and subfolder are in different fields, so they have to be replaced separately.

Next, the wp-config.php file has to be edited to match the new site URL and structure, as well as the database name and user credentials.

Finally, update the .htaccess file with the one given in the admin interface.

At first, I couldn’t get the site to work properly, the rewrites seemed to be going to the wrong place. Instead of localhost, there were going to localhost.com. I finally realised that this was due to an incorrectly configured value in wp-config.php. Once that was fixed, everything except the search function worked perfectly. The search function does not work because the form is hardcoded in the template to refer to the old URL. As I’m using the same symlink to the theme directory, I decided not to change it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s