Overview
WordPress hardcodes your site's domain name into the database in such things as image, link, and page URLs. This is a problem when you migrate the site to another domain name, or add an SSL certificate because clicking on links redirect back to the old site, or non-secure version.
If you even need to migrate your WordPress site to a different domain name, or add an SSL certificate to it, you must update the URLs in your database in order for your site to function. You have two options to update the URLs in your database:
- use a plugin
- use the command line
When changing URLs in WordPress, you must make sure the DreamHost panel does not conflict with your new URL settings by adding or removing www from the domain name. View the following article for information on how to ensure the panel is correctly configured.
- When changing URLs breaks WordPress
When to use these instructions
There are three reasons you will need to update the URLs in your database.
Reason | URL change |
---|---|
Moving to a different domain name | example.com to dreamhost.com |
Moving to a subdirectory | example.com to example.com/blog |
Adding an SSL certificate | http://example.com to https://example.com |
The instructions in this article are the same in all of these cases. The only difference will be the URLs you enter into the plugin or the command line.
This article adds HTTPS to the URL and changes the domain name to a subdirectory.
Option 1 — Using a plugin
Before you begin
The following section is also available as an instructional video:
Below are a couple of plugins that work to change all URLs in your database.
- Velvet Blues Update URLs
- Search and Replace
- Better Search Replace
The following steps walk you through how to update your URLs using the 'Search & Replace' plugin. This example changes the URLs in the database from http://example.com to https://example.com/blog.
- First, make a backup of your database. Just in case something goes wrong, you can easily replace your old database data.
- Download the Better Search Replace plugin. In your panel navigate to 'Plugins > Add New'.
- Search for 'Better Search Replace'.
- Click Install Now.
- Click Activate.
- In your Dashboard, navigate to the plugin under 'Tools > Better Search Replace'.
- Click the 'Search/Replace' tab.
- In the first field titled 'Search for:', enter your current http URL. For example:
- http://example.com
- In the second field titled 'Replace with:', enter your new URL. For example:
- https://example.com/blog
- Select all tables.
- You probably want to leave 'Replace GUIDs' UN-checked. View the following article for further details:
- Important GUID Note
- Check the box titled 'Run as dry run?'.
- Click Run Search/Replace.
- This should respond with a message at the top notifying you of what would have been updated if you did not check the 'Dry Run' box.
- If everything looks good, run it again with the 'Run as dry run?' box UN-checked.
- A confirmation will display notifying you of how many changes were made.
At this point, all URLs in your database point to your site's new URL.
Option 2 — Using the command line
Before you begin
The following section is also available as an instructional video:
If you are familiar with the command line, you can run the following command for the same effect (assuming you saved the old WordPress address).
- First, log into your server via SSH.
- Next, navigate to your WordPress directory. Make sure to change username to your Shell user. [server]$ cd /home/username/example.com
- In your site's directory, you can use wp-cli to update the URLs using the following command. [server]$ wp search-replace http://example.com https://example.com/blog --dry-run
The --dry-run call at the end tests the address
If the changes make sense to you, then run the above command again without the 'dry-run' call.
Clear your plugin's cache
At this point, you should also delete your cache if using WP Super Cache.
- Deleting the cache
If you check your site now, all URLs within your WordPress site will use the new domain name.
Final steps
At this point, all URLs in your database point to HTTPS, however, there are a few other steps you must take to fully ensure all links within your site point to the secure version of your domain name (This means the 'HTTPS' version).
View the following article for additional steps you should take to adjust your WordPress site to use an SSL certificate.
- How do I use an SSL certificate with WordPress?
See also
- How to log into your WordPress site