Five years ago, I installed this WordPress blog in a subdirectory at macmanx.com/blog/, imagining that someday I would have some sort of fancy website at macmanx.com, and that this would be nothing more than just a blog. Since then, I have spent quite a bit of time turning this blog into more than “just a blog.” About two weeks ago, I finally made the decision to move this blog out of macmanx.com/blog/ and put it where it belongs, at macmanx.com. The process was relatively simple using just phpMyAdmin, a plain text editor, and an FTP or SFTP client. There were no problems during the overall process, but the cleanup took a bit longer than expected. For the benefit of everyone reading this, I’d like to share my process, the problems that I ran in to after the move, and how I eventually resolved them.
The following instructions are Mac-specific using the plain text editor Fraise and the FTP/SFTP client Cyberduck, but they can be easily reinterpreted using any Windows or Linux-based plain text editor and FTP or SFTP client.
- Backup your WordPress database. (Never alter the database without a fresh backup on hand.)
- Download and install Fraise.
- Download and install Cyberduck.
- Go to Settings/General in your WordPress admin panel and change the two URL values to the new location.
- Export your WordPress database with phpMyAdmin.
- Open the .sql file in Fraise.
- Navigate to Edit/Find/Advanced Find & Replace, then find and replace all occurrences of “/old-directory” with “/new-directory”, or replace “/old-directory” with a blank field if you’re moving out of the old directory and into the root like I did. (You could make the task more specific by finding and replacing “yourdomain.com/old-directory” with “yourdomain.com/new-directory” etc, but this will only affect absolute URLs and completely ignore relative URLs.)
- Save the file and quit Fraise.
- Return to your WordPress database via phpMyAdmin.
- Check all of the tables and choose “Drop” from the pull-down menu.
- Navigate to the Import tab, choose your edited .sql file, and click the Go button.
- Access your server via Cyberduck and navigate to the blog’s directory.
- Select all of the files and move them to the new directory.
- Access your WordPress admin panel at the new location.
- Re-save your permalink structure at Settings/Permalinks in the admin panel.
- Re-save your upload directory at Settings/Miscellaneous in the admin panel.
- Edit (or create) the .htaccess file in your root directory with the following content: “Redirect permanent /old-directory/ http://www.yourdomain.com/new-directory/” or “Redirect permanent /old-directory/ http://www.yourdomain.com/” if you moved out of the old directory and into the root like I did.
- If you have a sitemap plugin, like Google XML Sitemaps, make sure that the sitemap location is still set correctly and refresh your sitemap.
Everything should be working perfectly. The whole process should only take a few minutes, but there is going to be some cleanup involved, and that may take a while.
You may notice that in step 7, we used Fraise to easily replace every reference to the old directory with the new directory, or we removed the references altogether. This is certainly easier than changing everything by hand via the admin panel, but it can be a bit destructive. For example, I used Fraise to completely remove all references to “/blog”. This had the desired effect of changing things like “macmanx.com/blog/about/” to “macmanx.com/about/” throughout the entire blog, which saved me the time of hand-editing almost 3,000 instances. Well, I’m sure some of you remember the Blogroll Dive, and how the links looked like “macmanx.com/blog/2007/11/blogroll-dive-11307/”. Unfortunately, they became “macmanx.com/2007/11/roll-dive-11307/”. Notice the problem? In order to fix this, I had to re-open the database in Fraise and find and replace all occurrences of “/roll-dive” with “/blogroll-dive”. This also affected some links to other blogs, but Google Webmaster Tools was kind enough to point out the problems after re-indexing the blog, so I corrected those via the admin panel.
All of that aside, the move went quite well, and the ease of using Fraise to find and replace almost 3,000 references to the old directory far outweighed any time lost during the cleanup afterwards.