How To Migrate Your WordPress Website
Estimated reading time: 1 min
In this article
- 1. 1. Backup Everything
- 2. 2. Copy Files to the Main Domain
- 3. Option A: If both the subdomain and the main domain share the same hosting account:
- 4. Option B: Different servers or accounts:
- 5. Update wp-config.php (if needed)
- 6. 4. Update Site URL in the Database
- 7. Option A: Use phpMyAdmin
- 8. Option B: Use WP-CLI
- 9. Option C: Add temporarily in wp-config.php
- 10. 5. Search and Replace URLs in Database
- 11. Tools:
- 12. 6. Fix Permalinks
- 13. Check and Test Everything
- 14. Optional: Update Google Search Console
1. Backup Everything
Before doing anything, back up:
- WordPress files (themes, plugins, uploads)
- Database
You can use plugins like UpdraftPlus and All-in-One WP Migration or do it manually via cPanel/phpMyAdmin.
2. Copy Files to the Main Domain
Option A: If both the subdomain and the main domain share the same hosting account:
- Use FTP or File Manager (in cPanel).
- Navigate to the subdomain directory (/public_html/sub or similar).
- Copy all files to the root directory (/public_html).
Option B: Different servers or accounts:
- Download all files from the subdomain.
- Upload them to the root directory of the main domain.
Update wp-config.php (if needed)
Usually, no changes are needed if you’re using the same database.
But if you moved to a different server/database, update the following in wp-config.php
4. Update Site URL in the Database
You need to change the site URL and home URL from the subdomain to the main domain.
Option A: Use phpMyAdmin
- Open your database.
- Go to the wp_options table.
- Change the values of:
- siteurl
- home
From: https://sub.example.com → https://example.com
Option B: Use WP-CLI
Option C: Add temporarily in wp-config.php
If you can’t access the dashboard
5. Search and Replace URLs in Database
Update all internal links and media URLs pointing to sub.example.com.
Tools:
- Plugin: Better Search Replace
WP-CLI
6. Fix Permalinks
- Log in to your WordPress dashboard at example.com/wp-admin.
- Go to Settings > Permalinks.
- Click Save Changes to regenerate .htaccess.
7. Redirect Subdomain to Main Domain (Optional)To maintain SEO and users, redirect old subdomain URLs.
- In the .htaccess of the subdomain folder
Check and Test Everything
- Visit https://example.com
- Check links, images, admin panel
- Test contact forms, plugins, and widgets
Optional: Update Google Search Console
- Add the main domain as a new property
Submit a new sitemap