Moving WordPress: Finding and Updating Old Paths
You’re moving your WordPress site to a new server, or to another folder on the same one. You’ve got all the files, the database config, etc., but the site’s still not working because WordPress stores the absolute path to your files and you haven’t found all the instances.
Where else do you need to look?
All Visible Files
grep -r '/old/path/to/wordpress' .
That should find any files you missed. And you can update them using sed:
xargs sed -i 's#oldpath#newpath#g' filename
If the results aren’t ambiguous and every instance of oldpath is definitely there to refer to a file, then you can combine grep and sed to get them all done at once:
grep -lr '/old/path/to/wordpress' . | xargs sed -i 's#oldpath#newpath#g'
Hidden Files
This is trickier, but fortunately there aren’t too many that are likely to be an issue. You’ll want to look at .htaccess
on an Apache site, of course. And if you’re using WordFence, you’ll want to check .user.ini
.
Database
You might think you could do a search and replace in the SQL database. But (a) that’s a freaking pain to do and (b) it wouldn’t work right, because A lot of fields in the WordPress database aren’t just plain values, they’re structures that PHP reads as objects.
If you have WP-CLI installed, you can just run this on the command line in your WordPress folder:
wp search-replace oldpath newpath
You may want to add --all-tables-with-prefix
if you have plugins that write to their own tables using complete file paths.
The Rest
That should be all the places you need to look for the old paths, and when I moved a site today, that was what it took to get it back online. This is only part of the process. Moving WordPress goes into a lot more detail on the other steps involved!