How to Change the Domain of a WordPress Site: A Comprehensive Guide
So, you’re ready for a new digital address? Maybe your branding has evolved, or you’ve simply found a domain name that better reflects your online presence. Changing the domain of a WordPress site might seem daunting, but with a methodical approach and a little know-how, you can pull it off smoothly and without losing your hard-earned SEO juice. The core process involves backing up your site, changing the WordPress address and site address URLs, updating the database, configuring redirection, and thoroughly testing the new domain. Let’s dive into each step with clarity and precision.
1. Backup, Backup, Backup!
Think of this as your digital safety net. Before even thinking about touching your website’s settings, create a complete backup of your entire WordPress site, including the database and all files. This allows you to revert to your original setup if anything goes wrong during the domain change.
- Option 1: Manual Backup: Access your site’s files via FTP (File Transfer Protocol) using a tool like FileZilla. Download all files and folders to your computer. Then, use phpMyAdmin (usually accessible through your web hosting control panel) to export your WordPress database as a
.sql
file. - Option 2: Plugin Power: Plugins like UpdraftPlus, BackupBuddy, and BlogVault are excellent for automated backups. They simplify the process and offer features like cloud storage integration for added security. Choose one that suits your needs and follow its instructions to create a full backup.
2. Change the WordPress Address and Site Address
This is where the magic begins. There are two primary ways to update your WordPress URLs: via the WordPress Admin Panel or by directly modifying the wp-config.php
file.
2.1. Method 1: WordPress Admin Panel
- Log in to your WordPress dashboard using your current domain (e.g.,
olddomain.com/wp-admin
). - Navigate to Settings > General.
- You’ll see two fields: WordPress Address (URL) and Site Address (URL).
- Carefully change both URLs to your new domain name (e.g.,
newdomain.com
). - Save Changes at the bottom of the page. You’ll likely be logged out as the URL has changed.
2.2. Method 2: Editing wp-config.php
This method is useful if you’re unable to access the admin panel.
Using FTP, connect to your website’s files.
Locate the
wp-config.php
file in the root directory of your WordPress installation.Download a copy of this file to your computer as a backup.
Open the
wp-config.php
file using a text editor.Add the following lines of code above the line
/* That's all, stop editing! Happy publishing. */
:define( 'WP_HOME', 'http://newdomain.com' ); define( 'WP_SITEURL', 'http://newdomain.com' );
Important: Replace
http://newdomain.com
with your actual new domain name (includinghttps://
if you have an SSL certificate).Save the changes to the
wp-config.php
file.Upload the modified
wp-config.php
file back to your server, overwriting the original.
3. Update the Database
While changing the WordPress and Site URLs addresses the core of the issue, your database may still contain references to the old domain. You need to update these to ensure everything functions correctly.
3.1. Method 1: Using a Plugin
Plugins like Better Search Replace and Search & Replace simplify this task.
- Log in to your WordPress dashboard using your new domain.
- Install and activate your chosen search and replace plugin.
- Go to the plugin’s settings page.
- In the “Search for” field, enter your old domain name (e.g.,
olddomain.com
). - In the “Replace with” field, enter your new domain name (e.g.,
newdomain.com
). - Select all the tables in your WordPress database (usually prefixed with
wp_
). - Important: Before running the actual replacement, select the “Run as dry run?” option. This will show you how many changes the plugin would make without actually applying them. Review the results carefully.
- If the dry run looks good, uncheck “Run as dry run?” and run the search and replace.
3.2. Method 2: Using phpMyAdmin
This is a more advanced method, but it gives you direct control over your database.
Access phpMyAdmin through your web hosting control panel.
Select your WordPress database.
Click on the “SQL” tab.
Enter the following SQL queries, replacing
olddomain.com
with your old domain andnewdomain.com
with your new domain:UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'siteurl' OR option_name = 'home'; UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');
Note: If your database table prefix is different from
wp_
, adjust the table names accordingly (e.g.,xyz_options
,xyz_posts
). If you are using SSL, usehttps
instead ofhttp
in the queries.Click “Go” to execute each query.
4. Set Up Redirections (301 Redirects)
This is crucial for SEO. 301 redirects tell search engines that your website has permanently moved to a new location. This ensures that you don’t lose any search engine rankings or traffic.
4.1. Using .htaccess
Connect to your website’s files via FTP.
Locate the
.htaccess
file in the root directory of your WordPress installation. If it doesn’t exist, create a new file named.htaccess
.Download a copy of this file to your computer as a backup.
Open the
.htaccess
file using a text editor.Add the following code at the beginning of the file:
#Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com$ RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Important: Replace
olddomain.com
with your old domain name andnewdomain.com
with your new domain name.Save the changes to the
.htaccess
file.Upload the modified
.htaccess
file back to your server, overwriting the original.
4.2. Using a Redirection Plugin
Plugins like Redirection and Yoast SEO Premium offer user-friendly interfaces for managing redirects.
- Install and activate your chosen redirection plugin.
- Follow the plugin’s instructions to create a 301 redirect from your old domain to your new domain. Most plugins will handle the
.htaccess
modifications automatically.
5. Test, Test, and Test Again!
Once you’ve completed the above steps, it’s time to thoroughly test your website.
- Browse your website: Click through all the pages and links to ensure everything is working correctly.
- Test forms and functionality: Make sure contact forms, e-commerce features, and other interactive elements are functioning as expected.
- Check images and media: Verify that all images and media files are loading properly.
- Use a redirect checker: Use online tools to confirm that 301 redirects are working correctly.
- Clear your browser cache: This ensures you’re seeing the latest version of your website.
6. Update Google Analytics and Search Console
Don’t forget to update your Google Analytics and Google Search Console settings with your new domain to track your website’s performance accurately. In Google Search Console, add the new domain as a new property.
Frequently Asked Questions (FAQs)
Here are some common questions related to changing a WordPress domain, answered with expert insight.
FAQ 1: How long does it take for the domain change to propagate?
DNS propagation can take anywhere from a few hours to 48 hours (sometimes even longer, though rare). During this time, some users might still see the old domain, while others see the new one. This is normal. Using a CDN can speed up propagation.
FAQ 2: Will I lose my SEO rankings when I change my domain?
If you implement 301 redirects correctly, you should not lose your SEO rankings. Search engines will eventually recognize the permanent redirect and transfer the link equity to your new domain. Monitor your rankings closely after the change.
FAQ 3: Should I change my domain during peak traffic hours?
It’s generally best to avoid changing your domain during peak traffic hours to minimize disruption to your visitors. Choose a time with lower traffic, such as late at night or early in the morning (based on your target audience’s time zone).
FAQ 4: What if I don’t have access to my old domain?
If you no longer have access to your old domain, you can’t implement 301 redirects. This will negatively impact your SEO. In this situation, focus on building high-quality content and promoting your new domain to regain your rankings.
FAQ 5: What if I’m moving to a new hosting provider at the same time?
Changing your domain and hosting provider simultaneously complicates the process. It’s best to do them separately. First, migrate your website to the new hosting provider using your old domain. Then, once the migration is complete and your site is working correctly, change the domain.
FAQ 6: What if I have an SSL certificate installed?
Make sure your SSL certificate is valid for your new domain. You may need to reissue or update your certificate after the domain change. Check with your hosting provider or SSL certificate provider for instructions.
FAQ 7: Do I need to update my email addresses after changing my domain?
Yes, you will need to update your email addresses to reflect your new domain. This usually involves creating new email accounts with your hosting provider or email service provider.
FAQ 8: How do I update my permalinks after changing my domain?
While not always necessary, it’s a good practice to regenerate your permalinks after changing your domain. Go to Settings > Permalinks in your WordPress dashboard and click “Save Changes.” This will update your .htaccess
file and ensure your permalinks are working correctly.
FAQ 9: Can I use a subdomain instead of a new domain?
Yes, you can use a subdomain (e.g., blog.newdomain.com
) instead of a completely new domain. The process is similar, but you’ll need to adjust the WordPress Address and Site Address URLs accordingly. However, using a subdomain is often viewed as less impactful for branding and SEO compared to a dedicated domain.
FAQ 10: How do I update hardcoded links in my theme files?
If you have any hardcoded links in your theme files (e.g., links to your logo or social media profiles), you’ll need to manually update them to reflect your new domain. Use FTP to access your theme files and edit them with a text editor.
FAQ 11: What if I encounter a “too many redirects” error after changing my domain?
This error usually indicates a conflict in your redirection rules. Double-check your .htaccess
file or redirection plugin settings to ensure that you don’t have conflicting redirects. Clear your browser cache and try again.
FAQ 12: Should I inform my users about the domain change?
It’s a good idea to inform your users about the domain change, especially if you have a large and engaged audience. You can post an announcement on your website, send an email to your subscribers, or share the news on social media. This helps to minimize confusion and ensures that your users can continue to access your content.
Leave a Reply