How to Search and Replace Old URLs in WordPress

How to Search and Replace Old URLs in WordPress
2026-05-28
admin

If you've changed your domain name, moved your site to HTTPS, or need to update links site-wide, you might need to search and replace old URLs in WordPress. Doing it manually can be time-consuming—and risky so let's find out how to do it safe and effective.

Common reasons for replacing old URLs:

  • Switching from 'http://' to 'https://';
  • Changing domain names (from 'oldsite.com' to 'newsite.com');
  • Moving from a subdomain or subfolder;
  • Correcting outdated or incorrect links in posts, pages, or widgets.

Important: Backup Your Website First.

Before making any changes to your database, always create a full backup of your site, including:

  • Database;
  • wp-content folder (themes, plugins, uploads);
  • wp-config.php.

You can use tools or your hosting provider's backup feature.

Use a Plugin (Recommended for Most Users)

Better Search Replace (Free)

One of the most popular and safe plugins.

1. Go to Plugins → Add New.

search and replace old URLs in wordpress add plugin

2. Search for Better Search Replace, install, and activate it.

search and replace old URLs in wordpress plugin

3. Go to Tools → Better Search Replace.

search and replace old URLs in wordpress tools

4. In the Search for field, enter your old URL (e.g., 'http://oldsite.com').

5. In the Replace with field, enter your new URL (e.g., 'https://newsite.com').

search and replace old URLs in wordpress replace urls

6. Select the tables you want to update (usually all).

7. First, run a dry run (checkbox at the bottom) to preview changes.

8. If all looks good, uncheck dry run and click Run Search/Replace.

This plugin handles serialized data, which is important for WordPress settings.

Use WP-CLI (For Advanced Users)

If you have command line access:

bash: wp search-replace 'http://oldsite.com' 'https://newsite.com' --all-tables

This updates all database entries. Safe and fast but for experienced users only.

Manual Search in phpMyAdmin (Not Recommended)

You can open your database using phpMyAdmin and run SQL queries like:

sql: UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://oldsite.com', 'https://newsite.com');

Warning: This is risky if you don't know SQL or if you're not familiar with how WordPress stores serialized data. Use a plugin instead unless you're very confident.

After the search and replace, verify:

  • Internal links work correctly.
  • Images display properly (check media library).
  • No redirects or broken links appear.
  • Your site URL and home URL (in Settings > General) match the new domain.

Update URLs in Theme or Widget Areas

If your theme or widgets contain hard-coded URLs, they may not be updated by the plugin. You can:

  • Manually update Appearance → Widgets or Customizer → Widgets.
  • Check for URLs in theme files (via Appearance → Theme File Editor or FTP).

Replacing URLs in WordPress is an essential task during site migrations, HTTPS upgrades, or domain changes. The safest and easiest method is using the Better Search Replace plugin. Just remember to back up first and test your site afterward to ensure everything works smoothly.

Other Worpress Articles that may be interesting for you: