When migrating a WordPress site to a new domain or URL, you need to update the site and home URLs in multiple places. Here are the most common and effective methods.
WP-CLI is the fastest and most reliable method for updating URLs:
# Update both home and site URL
wp option update home 'https://newdomain.com'
wp option update siteurl 'https://newdomain.com'
# Search and replace old URLs in content
wp search-replace 'https://olddomain.com' 'https://newdomain.com'
# Include uploads if you have hardcoded URLs in content
wp search-replace 'https://olddomain.com/wp-content/uploads' 'https://newdomain.com/wp-content/uploads'
# Flush rewrite rules
wp rewrite flushAdd these constants to your wp-config.php file before the /* That's all, stop editing! */ line:
// Force WordPress to use these URLs
define('WP_HOME', 'https://newdomain.com');
define('WP_SITEURL', 'https://newdomain.com');Note: This is a temporary solution. Remove these lines once you've updated the database permanently.
UPDATE wp_options
SET option_value = 'https://newdomain.com'
WHERE option_name = 'home';
UPDATE wp_options
SET option_value = 'https://newdomain.com'
WHERE option_name = 'siteurl';-- Update post content
UPDATE wp_posts
SET post_content = REPLACE(post_content, 'https://olddomain.com', 'https://newdomain.com');
-- Update meta values
UPDATE wp_postmeta
SET meta_value = REPLACE(meta_value, 'https://olddomain.com', 'https://newdomain.com');
-- Update comments
UPDATE wp_comments
SET comment_content = REPLACE(comment_content, 'https://olddomain.com', 'https://newdomain.com');If you can access the admin panel:
- Go to Settings > General
- Update WordPress Address (URL) and Site Address (URL)
- Save changes
Add to your theme's functions.php:
// Temporary URL override
update_option('siteurl', 'https://newdomain.com');
update_option('home', 'https://newdomain.com');Remove this code after the URLs are updated!
After updating URLs, verify these items:
- WordPress admin is accessible
- Frontend loads correctly
- Images and media files display properly
- Internal links work correctly
- SSL certificate is properly configured
- Redirect old domain to new domain (if applicable)
- Update any hardcoded URLs in theme files
- Check and update any plugins with domain-specific settings
- Update CDN settings if applicable
- Test contact forms and other functionality
If you can't access the admin after URL change:
- Use wp-config.php method first
- Then use WP-CLI or database method to make permanent changes
- Remove wp-config.php constants
If you're moving from HTTP to HTTPS:
# Use WP-CLI to replace HTTP with HTTPS
wp search-replace 'http://yourdomain.com' 'https://yourdomain.com'For WordPress multisite:
# Update main site
wp option update home 'https://newdomain.com' --url=olddomain.com
wp option update siteurl 'https://newdomain.com' --url=olddomain.com
# Update each subsite
wp search-replace 'olddomain.com' 'newdomain.com' --network- Always backup your database before making changes
- Use WP-CLI when possible - it's the safest method
- Test thoroughly after making changes
- Keep wp-config.php constants as temporary solutions only
- Update your DNS records and SSL certificates accordingly
- Set up 301 redirects from old domain to new domain if applicable