How to Clone a WordPress Site Without Broken Links
Cloning a WordPress site—moving it to a new domain or subdomain—usually results in a cascade of broken links and missing images because all URLs are hard-coded in the database. This guide walks you through a reliable method that updates every reference automatically, so your cloned site works exactly like the original. You’ll need access to your hosting file manager (or FTP), phpMyAdmin, and the WordPress admin dashboard on both sites.
What You’ll Need
- Access to the original site’s files (via FTP or hosting file manager)
- Access to the original site’s database (via phpMyAdmin or similar)
- A new domain or subdomain with hosting that supports PHP and MySQL
- An empty MySQL database for the new site (create it in your hosting control panel)
- A text editor (like Notepad++ or VS Code) for editing wp-config.php
- An FTP client (like FileZilla) if your host doesn’t have a file manager
Step-by-Step
- Back up the original site. In your hosting control panel, use the backup tool to create a full backup of files and database. If your host lacks that, download all files via FTP and export the database via phpMyAdmin (Export → Quick → Go). Store the backup safely.
- Create a new database and user. In the new hosting control panel, create a MySQL database and a user with all privileges. Note the database name, username, and password.
- Copy the files to the new location. Upload all the files from your original site’s root directory (usually public_html) to the new site’s root directory via FTP or file manager. If you’re using a subdomain, upload to that subdomain’s folder.
- Edit wp-config.php on the new site. Open the copied wp-config.php in a text editor. Replace the DB_NAME, DB_USER, and DB_PASSWORD constants with the new database credentials. Also check the DB_HOST—usually it’s ‘localhost’, but some hosts use a different hostname.
- Import the database. In phpMyAdmin for the new database, click Import, choose the SQL file you exported earlier, and click Go. Wait for the success message.
- Update the site URL in the database. In the new database’s phpMyAdmin, click on the wp_options table (the prefix may differ if you changed it). Find the rows where option_name is ‘siteurl’ and ‘home’. Click Edit on each and change the option_value to the new domain (e.g., https://newdomain.com). Save each.
- Search-replace all URLs in the database. This is the crucial step. Use a tool like Better Search Replace (a free plugin) or WP-CLI. If using the plugin: install it on the new site, go to Tools → Better Search Replace, enter the old domain (e.g., https://olddomain.com) in ‘Search for’ and the new domain in ‘Replace with’, select all tables, and run the dry run first. Then run the real replacement. If using WP-CLI, run:
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables. - Fix any remaining hard-coded links. Some themes or plugins store URLs in serialized data. The search-replace tool handles most, but check the wp_postmeta table for leftover old URLs. You can run a SQL query:
SELECT * FROM wp_postmeta WHERE meta_value LIKE '%olddomain.com%';and update those manually if needed. - Update .htaccess and permalinks. If your new site uses a different directory structure, edit the .htaccess file (it may be hidden) to match the new path. Then log into the WordPress admin on the new site, go to Settings → Permalinks, and click Save Changes to flush the rewrite rules.
- Test thoroughly. Visit the new site’s homepage, click through several pages, check images, and try a search. Use a tool like Broken Link Checker (plugin) or an online crawler to find any remaining broken links. Also check the admin area and any forms.
Common Mistakes
- Using a simple find-and-replace in the database dump. This breaks serialized data because the lengths of strings change. Always use a tool that handles serialization, like Better Search Replace or WP-CLI.
- Forgetting to update the siteurl and home options. If you skip this, the site will redirect to the old domain.
- Not updating wp-config.php. The new site will try to connect to the old database, causing errors.
- Copying files to the wrong directory. Double-check the new site’s document root.
- Leaving old domain in the .htaccess file. This can cause redirect loops.
Tips
- Do a dry run with Better Search Replace before the real one to see how many changes will be made.
- Use a staging site if possible to test the clone before going live.
- Keep the old site live until the new one is fully tested.
- After the clone, update any hard-coded URLs in your theme’s custom code or widgets.
- If you’re moving to HTTPS, also replace http:// with https:// in the same search-replace step.
Troubleshooting
Site shows “Error establishing a database connection.� Check wp-config.php credentials and that the database exists. Verify the DB_HOST value—some hosts use a specific hostname like ‘mysql.hosting.com’.
Pages load but images are broken. The search-replace didn’t catch all URLs. Re-run Better Search Replace, ensuring you include the http/https variations. Also check the wp_postmeta table for serialized data.
Login redirects to old domain. The siteurl/home options weren’t updated correctly. Go to the new database’s wp_options table and set both to the new domain.
Plugins or theme show errors. Some plugins store absolute paths. Re-run the search-replace with the full path (e.g., /home/user/public_html) replaced with the new path. Also clear any cache plugins.
Permalinks give 404 errors. Go to Settings → Permalinks and click Save Changes. If that fails, edit .htaccess manually to include the standard WordPress rewrite rules.
Frequently Asked Questions
Can I clone a WordPress site without a plugin?
Yes, you can do it manually using FTP and phpMyAdmin as described. It’s more work but gives you full control.
Will the search-replace break my site?
If you use a tool that handles serialized data (like Better Search Replace), it’s safe. Avoid simple find-replace in a text editor.
Do I need to change the WordPress salts?
No, but it’s a good security practice. You can generate new salts from the WordPress salt generator and update wp-config.php.
What if my new domain uses a different protocol (http vs https)?
Include the protocol in the search-replace. For example, replace http://olddomain.com with https://newdomain.com.
How do I handle a site with a lot of media files?
The search-replace updates the URLs in the database, so the media library will work. Just make sure all files are uploaded to the correct paths.
Can I clone a WordPress site to a local server?
Yes, the process is similar. You’ll need to set up a local environment like XAMPP or Local by Flywheel, and use ‘localhost’ as the domain in the search-replace.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.