9 Easy Steps To WP-CLI Change Site URL
Bulletproof Backups for Your WordPress Website
Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.
Moving from staging to live? Switching hosts? Launching a rebrand? Using WP-CLI makes the URL change quick and clean.
But it’s not enough to just use the WP-CLI change site URL commands to migrate your WordPress site. Your old URLs hide in places like the posts, widgets and plugin settings. If you miss any of those embedded old URLs, you’ll have mixed content issues.
We’ve fixed countless botched migrations. The same mistakes happen over and over. This guide covers the complete workflow. From URL changes to replacing the old URLs, we’ve got your back.
TL;DR: Before you change your URL with WP-CLI, take a full backup using a WordPress backup plugin. Connect to your server and navigate to your WordPress root. Run the following commands in order:
wp option update siteurl ‘https://yournewdomain.com’
wp option update home ‘https://yournewdomain.com’
There could be a wide variety of reasons why you are looking to change your site URL using WP-CLi. Are you migrating to a new domain that you recently bought or maybe you’re moving from staging to live. Either way, it’s important to handle the migration carefully to avoid losing traffic.
Prerequisites for the WP-CLI change site URL
These steps aren’t suggestions. They’re requirements. Skip any of these and your URL change will either fail completely or create bigger problems than you started with.
- Take a full backup: You can take a WP-CLI backup or use a WordPress backup plugin like BlogVault. Make sure to backup all your site files and your database tables. This lets you restore your site if things go wrong.
- SSH access: Confirm you have SSH access to your server. Most hosting providers include this in cPanel or their dashboard. You should have the right credentials too (username, password and IP address)
- Valid domain: If you haven’t already, purchase and configure your new domain completely. Buy the domain from your registrar, then update DNS settings to point it to your hosting server’s IP address.
- Valid SSL certificate (If required): If you’re moving from HTTP to HTTPS, install a valid SSL certificate on the new domain. Most hosts offer free Let’s Encrypt certificates through their control panels. Get HTTPS working on your new domain before changing WordPress URLs.
Note: These instructions work on Mac and Linux systems. Windows users need a few adjustments – use Command Prompt or PowerShell instead of Terminal, and you might need an SSH client like PuTTY to connect to your server. The WP-CLI commands themselves stay exactly the same once you’re connected.
Using WP-CLI change site URL
The whole process boils down to three commands that will update the core WordPress options first, and replace the URL references. This reduces migration failures.
- Connect to Your Server via SSH: Use the SSH credentials in the following command:
ssh username@server-ip
Type your password when prompted.
- Navigate to Your WordPress Directory: Move to your WordPress root folder:
cd public_html
Some hosts use different folder names like www or httpdocs. Use ls to list directories if you’re unsure.
- Check Your Current Site URL: See what URLs WordPress is currently using:
wp option get siteurl
wp option get home
Write these down. You’ll need them if something goes wrong and you need to revert.
- Change the Site URL: Update WordPress to use your new domain:
wp option update siteurl 'https://yournewdomain.com'
wp option update home 'https://yournewdomain.com'
Replace yournewdomain.com with your actual new domain. Include https:// if you’re using SSL.
- Setup 301 Redirects: Add redirect rules to send old traffic to your new domain:
wp eval 'file_put_contents(ABSPATH.".htaccess", "RewriteEngine On\nRewriteCond %{HTTP_HOST} ^oldsite\.com$ [NC]\nRewriteRule ^(.*)$ https://newsite.com/$1 [L,R=301]\n", FILE_APPEND);'
Change oldsite.com to your old domain and newsite.com to your new one. This works on Apache servers with .htaccess support.
- Search and replace old URLs: Run the WP-CLi search replace command to update all mentions of the old URL on your database.
wp search-replace 'http://oldsite.com' 'https://newsite.com' --skip-columns=guid
The –skip-columns=guid flag prevents breaking WordPress’s internal post identification system. Always include this flag.
- Flush Permalinks: Regenerate your site’s URL structure:
wp rewrite flush
This ensures all your pages and posts load correctly with the new domain.
- Confirm the Change: Verify your new URLs are active:
wp option get siteurl
wp option get home
Both commands should return your new domain. If they don’t, something went wrong.
- Clear Cache: Remove any cached versions of your old URLs:
wp cache flush
This clears WordPress’s built-in cache. You may also need to clear caching plugins separately.
Alternative Methods to WP-CLI Change Site URL
WP-CLI isn’t always an option. Some shared hosts don’t support it, or you might be working with a client who only has basic cPanel access. Here are some other options:
Option 1: Using Plugins
Better Search Replace is the safest plugin option for URL changes. Install it from your WordPress admin, go to Tools > Better Search Replace, and enter your old and new URLs. Run it with “Dry Run” checked first to preview changes.
The plugin handles serialized data automatically, which is where manual find-and-replace methods usually break. It’s slower than WP-CLI but much safer than editing your database directly.
Option 2: Manual Database Update
Edit the wp_options table only if you’re comfortable with WordPress databases. Log into phpMyAdmin, find your WordPress database, and open the wp_options table. Look for rows where option_name equals “siteurl” and “home,” then update the option_value to your new URL.
⚠️Warning ⚠️
This method is risky. One typo can break your entire site. Always backup your database first. If you’re not confident working in phpMyAdmin, use a plugin instead.
Option 3: wp-config.php Override
Add these lines to your wp-config.php file to force WordPress to use new URLs:
define('WP_HOME', 'https://newdomain.com');
define('WP_SITEURL', 'https://newdomain.com');
Place these lines above the “That’s all, stop editing” comment.
🔔 Expert Advice 🔔
This method overrides whatever URLs are stored in your database. It’s useful for emergency access when your admin is broken, but remember to update your actual database URLs later and remove these lines.
Final Thoughts
Changing your site URL is serious business. We’ve seen too many migrations turn into multi-day recovery projects because someone rushed through the process or skipped the backup step. That’s why we recommend that you take a full backup first.
However, you should know that the WP-CLI method we’ve covered here works reliably when you follow the steps in order. We’ve used this process on hundreds of migrations. Work carefully through each step.
FAQs:
How to change WP site URL?
Use WP-CLI for the most reliable method. Connect via SSH, navigate to your WordPress directory, then run wp option update siteurl ‘https://newdomain.com’ and wp option update home ‘https://newdomain.com’. Follow up with wp search-replace to update database references and wp rewrite flush to fix permalinks.
How do I edit a URL link in WordPress?
For individual post/page URLs, edit the permalink in your post editor. Click “Edit” next to the URL under your post title. For menu links, go to Appearance > Menus and update the URL field.
If you mean changing links within your content, use the search-replace method: wp search-replace ‘old-link.com’ ‘new-link.com’ updates all instances across your database.
What’s the difference between Site address and WordPress address?
WordPress address (siteurl) is where your WordPress files live. Site address (home) is what visitors see in their browser. Most of the time these are identical, like https://yoursite.com.
They differ when WordPress is installed in a subdirectory but you want your site to display at the root domain. For example, WordPress files might be at https://yoursite.com/wp/ but visitors see https://yoursite.com.
Alternatively, use plugins like Better Search Replace or manually edit your wp-config.php file with URL definition
How do I move a WordPress site to another URL?
Follow the complete migration process: backup your site, set up the new domain with DNS and SSL, use WP-CLI to update WordPress URLs (wp option update siteurl and wp option update home), run search-replace for database content, set up 301 redirects, and clear all caches.
Don’t change WordPress URLs until your new domain is fully configured and accessible.
What to do after changing the site URL?
Clear all caches first with wp cache flush plus any caching plugins. Set up 301 redirects from your old domain to prevent broken links. Test your site thoroughly – check admin access, media files, and internal links.
Monitor for mixed content warnings if you switched to HTTPS. Update any external services like CDNs, analytics, or third-party integrations that reference your old URL.
Tags:
Share it:
You may also like
15+ WordPress Plugins Your Site Will Thank You For
If you have spent more than ten minutes looking for WordPress plugins, you have probably seen the same pattern. Long lists. Mixed advice. Too many must-have tools that most sites…
Error Establishing a Database Connection? Fix It In 10 Mins
You open your site and see Error Establishing a Database Connection message. It is a rough moment, but it is usually fixable. In most cases, your posts, pages, and media…
Solved: WordPress Keeps Logging Me Out! 7 Ways to Fix This issue
There is nothing minor about it when WordPress keeps logging you out. It interrupts your work, creates repeated login issues, and makes even basic changes to your site feel unreliable….
How do you update and backup your website?
Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.
Updating Everything Manually?
But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.
Backup Your WordPress Site
Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.