There are several ways for replacing URLs when it comes to your site. But the simplest is using commands when you’re logged in via SSH. For WordPress sites we do have WP-CLI installed on all our servers which comes with a very handy command. You can find more information on that in our article about updating URLs in database.
But other content management systems might not have it that simple. There is an alternative method!
Time needed: 5 minutes.
Search and replacing URLs via the command line can be done in with the following steps:
- First make a dump file of your database
make a dump file of your database, preferably in your
~/privatedirectory. Here’s the command for that:
mysqldump --single-transaction -u DATABASE_USER -p DATABASE_NAME > ~/private/DB_DUMP.sql
- Make a copy of the database
We recommend you make a copy of the file and make the changes to the new copy. This way you can always revert back:
cp ~/private/DB_DUMP.sql ~/private/NEW_DB_DUMP.sql
- Search and Replace all matching strings
sedcommand to search and replace all matching strings within the DB dump file:
sed -i 's+OLD-URL+
- Import the new updated dump file
As a last step, simply import the new updated dump file:
mysql -u DATABASEUSER -p DATABASENAME < NEW_DB_DUMP.sql
Check that everything works. Remember that you might need to flush browser cache and cookies. If it breaks something you can always revert back to the original dump file you made!
Do you have any additional questions please contact our support team at servebolt.com!
Give us your feedback on this article
Want to speed up your site, easily?
Set up your site on Servebolt, free of charge for 60 days, and see for yourself how fast it can be on our extremely fast hosting.
A faster site converts better, ranks better on Google, and is better for the climate.