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
Servebolt’s new plans and pricing model put a greater focus on customization and flexibility while taking advantage of our amazing performance and scalability.
✅ More storage included in all plans
✅ Lower storage pricing
✅ More cost efficient scaling of traffic and Dynamic Requests
✅ More production environments in all plans
✅ More Servebolt CDN hostnames included in all plans