Why does this happen?
A URL is a web address, like https://www.example.com. Apps such as WordPress save your address inside the database. A database is a store where the site keeps its information.
When you move to a new domain, the files move. But the old address stays inside the database. Then pages, images and links may still point to the old place. Visitors may see broken images or land on the old site.
Before you start
Warning: editing a database can break your site. Take a full backup of the files and the database first. Keep a copy on your own computer.
To make a backup in phpMyAdmin, pick your database, click Export, then Export again.
Way 1: a plugin (for WordPress)
A plugin is an add-on. This is the safest way for beginners. A search-and-replace plugin handles tricky data for you.
- Log in to your WordPress dashboard.
- Click Plugins, then Add New.
- Search for a search-and-replace plugin, such as Better Search Replace.
- Click Install Now, then Activate.
- Go to Tools, then Better Search Replace.
- In Search for, type the old address.
- In Replace with, type the new address.
- Select all tables.
- Tick Run as dry run? and click Run Search/Replace. This only shows what would change.
- If the result looks right, untick the dry run box and run it again.
Way 2: SQL in phpMyAdmin
SQL is the language used to talk to databases. This way fits simple changes. Be careful with saved settings: some store text in a special format that breaks if you change it by hand. For that reason, use a plugin or tool for WordPress.
- Open phpMyAdmin from your control panel.
- Click your database in the left panel.
- Click the SQL tab.
- Type a command like this. Use your own table name and addresses:
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://old-site.com', 'https://new-site.com');
This replaces the old address with the new one in the text of all posts.
- Click Go.
The table prefix, here wp_, may differ on your site.
Fix the main site address
In WordPress, go to Settings, then General. Check WordPress Address and Site Address. If you are locked out, you can fix them in the wp_options table.
Quick recap
- Old URLs stay in the database after a move.
- Back up the files and database first.
- Use a search-and-replace plugin or an SQL command.
- Test with a dry run, then check your site.