WordPress Migration to a Subdir

Recently, kenlon.com moved its WordPress instance to a subdir on the
same server. The actual move appeared to be simple:

$ mv wp ed/wp

Done.

Well, almost. We also went into the admin dash and updated the Permalink
URL in Settings > Permalinks.

At first glance, everything worked.

Later, as we browsed around, we discovered that some paths to images had
not gotten updated. Presumably the WP devs have good reasons for
not updating image paths relative to the WP install, so this is
something that the site maintainer must do manually. Or semi-manually.

The solution was a quick fix, detailed more verbosely in WP’s docs: https://codex.wordpress.org/Moving_WordPress

What I did was this:

  1. First, backup the WP database on the server:
    $ mysqldump -u myUserName -h localhost -p myDataBaseName >
    backupWpDb-`date +%s`.sql
  2. Next, install Better Search Replace plugin.
  3. Use the Better Search Replace plugin (now found in the Tools menu
    of the WP dash) to search for the old URL string and replace it with the
    new. In our case, this meant searching for ‘kenlon.com/wp’ and replacing
    with ‘kenlon.com/ed/wp’
  4. Run the search and replace in dry-run mode first. Confirm that its
    results make sense. And then run it for real.

All fixed. Easy as.

This entry was posted in IT, Linux. Bookmark the permalink.

One Response to WordPress Migration to a Subdir

  1. RedRider06 says:

    Well, whaduhyano? This has been here a long time and I’m just now discovering it. Shame, shame. I am way behind in my technical reading. Thanks for putting up the “how-to.” I’m sure it will come in handy again someday.

Comments are closed.