Blog · WebJi® India

WordPress Search and Replace URLs

Quick answer: A WordPress search and replace updates every old URL stored in the database, including builder and widget data that records each string's length. Use WP-CLI or the Better Search Replace plugin, and dry-run before you write. A plain SQL UPDATE skips those lengths and can wipe layouts. Take a database backup first.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Small Indian startup team gathered around a laptop discussing their email inbox — wordpress search and replace urls

When a URL replace is required

WordPress stores the site address in more than the address bar. The home and site URL live in settings, and posts, widgets and page builders store full links inside the database. After a domain move, a shift from http to https, or a copy onto a staging host, those stored links still point at the old address.

Change the two settings fields only when you are sure nothing else embeds the old host. On a site that has been edited for a while, run a database replace. The steps below sit next to WordPress hosting moves and the domain change walkthrough.

Why a plain SQL update breaks serialized data

Some plugin and theme settings are stored as PHP serialized strings. The string records how many characters the value has. If you change the domain with a raw SQL replace, the character count stays at the old number, the value no longer parses, and WordPress drops it. Widgets, builder layouts and theme options then look empty even though the row is still in the table.

WP-CLI and Better Search Replace unpack the value, change the URL, write the new length and pack it again. Use a raw SQL statement only for a plain text column you have inspected. Do not run it across every table.

Small Indian startup team gathered around a laptop discussing their email inbox — wordpress search and replace urls

Dry-run the replace with WP-CLI

  1. Export the database, or take the host backup, and keep that file off the server.
  2. From the WordPress directory, dry-run: wp search-replace 'https://old.example' 'https://new.example' --all-tables --dry-run
  3. Read the table report. A count of zero on a content table means the old host is not in that table, which is fine.
  4. Run the same command without --dry-run only after the report looks right.
  5. If WP-CLI is not installed, use the plugin in the next section. Do not invent a manual SQL pass to skip the dry run.

Do this on one site or on staging first. Email support@webji.services with the command and the error text if the dry run itself fails. Phone +91 141 4941811 is business hours only.

Better Search Replace in wp-admin

  1. Install the Better Search Replace plugin and open Tools, then Better Search Replace.
  2. Put the old URL in the search field and the new URL in the replace field. Match the scheme and the host, and skip a trailing slash unless both sides have one.
  3. Select the tables. Tick the dry-run box and run it.
  4. Untick dry run and run again only after the preview counts look right.
  5. Deactivate the plugin when you are finished so it is not left on a public site.

Tables to include and tables to leave

TableWhat to do
wp_optionsInclude. This holds siteurl, home and many plugin settings.
wp_postsInclude. Post content and excerpts store links.
wp_postmetaInclude. Builders and widgets store URLs here.
wp_commentsInclude only if comment text contains your old links.
Log or cache tablesSkip. They are not the live site, and a replace there wastes time.

The prefix may not be wp_. Use the prefix in your wp-config.php. GUID values in posts are historical identifiers. Leave them unless you know a feed already broke, and do not treat a GUID change as the way to fix the visible site.

HTTP to HTTPS URL checklist

  • Install the certificate and confirm the site opens on https.
  • Replace http://example.com with https://example.com using the dry run above.
  • Set both WordPress address fields to the https host.
  • Redirect the http host to https so old links land once. The HTTP to HTTPS guide covers that redirect.

Check the site after the replace

  1. Open Settings, then General. Both URL fields must show the new host.
  2. In a private window, open the home page, one post, one image and one form.
  3. Look at a widget and a menu. Empty widget areas usually mean a serialized row was damaged.
  4. If a builder layout is blank, restore the database backup and repeat with a length-aware tool. Do not run a second raw SQL update on top.

A move between hosts is the same replace after the files and database are copied. See the Hostinger migration notes for the copy itself.

Frequently Asked Questions

How do I search and replace URLs in WordPress?

Back up the database, then dry-run WP-CLI search-replace or the Better Search Replace plugin from the old URL to the new URL. Run it for real only after the preview counts look right.

Why can't I just use SQL UPDATE to change URLs?

A plain replace does not update the character counts stored inside PHP serialized settings. Widgets and page-builder layouts can come back empty. Use WP-CLI or Better Search Replace, which rewrite those lengths.

What is serialized data in WordPress?

It is a PHP text format that stores an array or object and writes the length of each string inside the text. Changing the URL without changing that length makes WordPress discard the value.

How do I change my WordPress URL from http to https?

Turn on the certificate, replace http://example.com with https://example.com using a dry run, set both settings URLs to https, and redirect the http host. The HTTP to HTTPS guide covers the redirect.

Which plugin is best for search and replace?

Better Search Replace is the usual plugin when you do not have WP-CLI. Run its dry-run box first, then the live pass, and remove the plugin afterwards.

How do I use WP-CLI search-replace?

From the WordPress directory run wp search-replace with the old URL, the new URL, --all-tables and --dry-run. Drop --dry-run for the live write after you have a backup and the report looks right.

Is WebJi® an Indian company?

Yes. WebJi® is headquartered in Jaipur, Rajasthan and has operated since 2005. Billing, support and governance all run from India.

Do you provide GST invoices?

Every purchase and renewal gets a GST invoice with our GSTIN, and hosting prices are quoted exclusive of 18% GST. Claim input credit as applicable.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →