![]() Replacing URL encoded strings sed 's #http%3A%2F%2F #http%3A%2F%2F #g' dump.sql > staging-or-newdomain.sql In this example, there is a subfolder for the WordPress installation, the # helps maintan readability sed 's # /oldfolder # /newfolder #g' dump.sql > staging-or-newdomain.sql URL Encoded This command replaces with in the dump.sql file sed 's #g' dump.sql > staging-or-newdomain.sql ![]() The g signifies a global replacement and the > redirects to a new file so you do not modify the original database dump. It also means you will not have to escape any slashes ( \/) in your sed command. Many tutorials use / as the delimiter for sed, I am using # to make it easier to read. Sometimes plugins store information about the storage path on your host, find out by using this command grep -c ' /public_html/' database.sql Actual replacement ![]() grep -c 'http:\/\/ ' database.sql WordPress Path Some plugins escape slashes with \/ and can easily be missed because of the serialized content in json format. To verify whether you have any of these in your database use this command grep -c ' http%3A%2F%2F' database.sql Serialized Arrays – Escaped Slashes Some plugins use URL encoding which uses this format for http and https migration %3A = : and %2F = /. You will get an integer as output, if you see 0 then there are no occurrences of in the database 4513 URL Encoded We can simulate a dry run with grep, using the -c flag it will count the amount of times it finds the string grep -c '' database.sql If you do not have access to Linux then you can use the WordPress plugin Better Search and Replace. I am going to use the Linux tools grep and sed for maximum speed. Advanced WordPress Search Replace Database with Linux using sed I will assume you already have a WordPress database dump created with phpMyAdmin, Adminer ( plugin), MySQL dump or WP-CLI. I first encountered this issue when I discovered a plugin (looking at you Ultimate VC Add-ons) likes to encode the colon and slashes differently like this http%3A%2F%2F Traditionally there are some plugins and scripts that help you update the database to resolve these issues, if you still have problems this post should help you fix paths and URLs in your WordPress database. Similarly when switching from http to https you may get some mixed content errors, usually this can be fixed by updating the database. When you migrate a WordPress site or WooCommerce store to a new domain you may find some URLs or paths were not updated.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |