Before You Begin: Essential Preparations
Setting up a full site redirect requires careful planning. Before you make any changes, ensure you've completed the following:
Backup Your WordPress Site: This is non-negotiable. Before making any significant changes to your site's configuration or database, create a complete backup of your WordPress files and database. This will allow you to revert to a previous state if anything goes wrong. Many hosting providers offer backup solutions, or you can use a WordPress backup plugin like UpdraftPlus or BackWPup.
Set Up Your New WordPress Site: Ensure your new WordPress installation is fully set up, configured, and tested. All content should be migrated, plugins installed, and themes activated.
Update Internal Links: Once your new site is ready, go through your content and update all internal links using the Better Search Replace plugin to reflect the new domain or URL structure. This is crucial for user navigation and SEO.
Inform Your Audience (Optional but Recommended): If you have a large audience, consider informing them about the upcoming domain change through email newsletters, social media, or a prominent notice on your old site. This can help manage expectations and reduce confusion.
Clear Caches: Before testing your redirects, clear all caches (browser, WordPress caching plugins, server-side caching) to ensure you're seeing the most up-to-date version of your site.
How to Set Up a Full Site Redirect in WordPress
There are several ways to implement a full site redirect in WordPress, ranging from simple plugin solutions to more advanced server-level configurations. This article includes two methods.
For most WordPress users, a plugin is the easiest and safest way to set up redirects. Plugins abstract the complexities of server configuration and provide a user-friendly interface.
Popular Redirect Plugins:
Rank Math SEO: While primarily an SEO plugin, Rank Math includes a powerful Redirections module.
Yoast SEO Premium: Similar to Rank Math, Yoast SEO Premium offers a redirect manager as part of its paid features.
Redirection: This dedicated redirect plugin is highly popular and free. It allows you to manage 301, 302, and 307 redirects, monitor 404 errors, and set up advanced redirect rules.
Simple 301 Redirects: As its name suggests, this plugin offers a straightforward interface for creating 301 redirects.
As a note, please only choose one of the above for your redirects as they could conflict against each other. If you are already using the free version of Yoast SEO, it is safe to use the Redirection plugin. However, if you are using Yoast SEO Premium, it will conflict with the Redirection plugin.
How to Use the Redirection Plugin (Example):
Install and Activate: From your WordPress dashboard, go to ‘Plugins > Add New’, search for "Redirection," install, and activate it.
Access Redirection Settings: Go to ‘Tools > Redirection’.
Set Up a New Redirect:
a. In the "Source URL" field, enter the URL of your old site. For a full site redirect, you'll typically use a wildcard to capture all old URLs. For example, if you're moving from ‘olddomain.com’ to ‘newdomain.com’, you might enter ‘/.*’ in the Source URL field.
b. In the "Target URL" field, enter the URL of your new site. For a full site redirect, you'll enter your new domain, for example - ‘https://newdomain.com/’.
i. Make Sure the "Group" is set to "Redirections."
ii. Set the "HTTP Code" to "301 - Moved Permanently."
iii. Click "Add Redirect."
Test Your Redirect: After setting up the redirect, clear your browser cache and try accessing URLs from your old domain. They should automatically redirect to your new domain.
Important Note on Wildcards: When redirecting an entire domain using a plugin like Redirection, you'll often need to set up two rules for comprehensive coverage:
Rule 1: Redirecting the old domain (excluding subdirectories) to the new domain:
a. Source URL: ‘^/’
b. Target URL: ‘https://newdomain.com/’ (Make sure to check "Regex" or "Regular expression" option if available in the plugin settings for these rules)
c. HTTP Code: 301
Rule 2: Redirecting all subdirectories and files from the old domain to the new domain, maintaining the path:
a. Source URL: ‘^/(.*)’
b. Target URL: ‘https://newdomain.com/$1’ (Again, ensure "Regex" is enabled)
c. HTTP Code: 301
This setup makes sure that ‘olddomain.com’ goes to ‘newdomain.com’ and ‘olddomain.com/some-page’ goes to ‘newdomain.com/some-page’.
The .htaccess file is a powerful configuration file used by Apache web servers. It allows you to control various aspects of your website's behavior, including redirects. This method is highly efficient but requires more technical knowledge and careful execution, as errors can break your site.
Before you start:
Locate your .htaccess file: It's usually found in the root directory of your WordPress installation (example - ‘public_html’). You can access it via FTP/SFTP or your hosting provider's file manager.
Make a backup: Always download a copy of your ‘.htaccess’ file before editing it.
Common Scenarios and .htaccess Rules:
Scenario A: Redirecting an Entire Domain to a New Domain
This is the most common full site redirect.
Redirect olddomain.com to newdomain.com
RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com$ RewriteRule (.*)$ https://newdomain.com/$1 [R=301,L]
Explanation:
‘RewriteEngine On’: Activates the Apache rewrite module.
‘RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]’: This condition checks if the requested host is ‘olddomain.com’. The ‘\’ before the dot escapes it, treating it as a literal dot. ‘[OR]’ means "or the next condition."
‘RewriteCond %{HTTP_HOST} ^www.olddomain.com$’: This condition checks if the requested host is ‘www.olddomain.com’.
‘RewriteRule (.*)$ https://newdomain.com/$1 [R=301,L]’: This is the rewrite rule itself.
a. ‘(.*)’: Captures everything after the domain in the URL.
b. ‘https://newdomain.com/$1’: The target URL. ‘$1’ refers to the captured content from ‘(.*)’, ensuring that individual pages (example - ‘olddomain.com/about-us’) redirect to their counterparts on the new domain (example - ‘newdomain.com/about-us’).
c. ‘[R=301,L]`:
i. ‘R=301’: Specifies a 301 (permanent) redirect.
ii.‘L’: Stands for "Last rule," meaning if this rule is met, no further rewrite rules will be processed.
Where to place this code:
Place this code ABOVE the ‘# BEGIN WordPress’ and ‘# END WordPress’ markers in your ‘.htaccess’ file.
Scenario B: Redirecting Non-WWW to WWW (or vice-versa)
If you want all traffic to go to the WWW version of your site:
Redirect non-WWW to WWW
RewriteEngine On RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
If you want all traffic to go to the non-WWW version of your site:
Redirect WWW to non-WWW
RewriteEngine On RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC] RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Scenario C: Migrating from HTTP to HTTPS
Force HTTPS
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
After Setting Up the Redirect: Important Post-Redirect Steps
Setting up the redirect is only half the battle. To ensure a successful migration and maintain your SEO, follow these post-redirect steps:
Test Thoroughly: This is VERY important.
a. Clear your browser cache.
b. Test various URLs from your old domain (homepage, old posts/pages, categories, tags, images, non-existent URLs) to ensure they all correctly redirect to your new site.
Use online redirect checker tools like HTTP Status Code Checkeror Redirect Checker to verify that a 301 status code is returned.
Update Google Search Console:
a. Add your new domain as a property in Google Search Console.
b. Use the "Change of Address" tool in your old domain's Search Console property to notify Google about the site move. This significantly speeds up the reindexing process.
c. Monitor the "Crawl Errors" section for your old domain for any 404 errors that might indicate missed redirects.
d. Monitor "Performance" for both properties to track traffic and keyword rankings.
Update Google Analytics:
a. If you're using Google Analytics, make sure your new site is tracking correctly. If you're using the same tracking code, ensure the domain settings are updated.
b. Consider annotating the date of the redirect in your Google Analytics account to easily identify any changes in traffic patterns.
Update Sitemaps:
a. Generate a new sitemap for your new site using an SEO plugin like Rank Math or Yoast SEO.
b. Submit this new sitemap to Google Search Console.
c. Remove your old sitemap or point it to the new sitemap if still accessible.
Update External Links (Where Possible):
a. Reach out to websites that link to your old domain and ask them to update the links to your new domain. This is especially important for high-authority backlinks.
b. Update any social media profiles, business directories, and other online presences with your new domain.
Monitor Your Site:
a. Keep a close eye on your website's performance, traffic, and search engine rankings for several weeks after the redirect.
Be prepared to troubleshoot any unexpected issues.
Common Problems and Troubleshooting
Here are some issues you could possibly run into and some quick tips to resolving them.
Redirect Loops: This occurs when a URL redirects back to itself, often due to conflicting redirect rules. Clear your browser cache and carefully review your redirect configurations.
Too Many Redirects: Similar to loops, this happens when a request goes through multiple redirects before reaching the final destination. This can slow down your site and negatively impact SEO. Simplify your redirect chains.
Incorrect Redirect Type (302 vs. 301): A 302 redirect is temporary, while a 301 is permanent. Using a 302 for a permanent move will prevent the transfer of SEO value. Always use 301 for permanent changes.
Caching Issues: Server-side caching, CDN caching, and browser caching can interfere with testing redirects. Always clear all caches before testing.
Forgetting HTTPS: If you're moving to HTTPS, ensure all your redirects go to the HTTPS version of your new site.
Case Sensitivity: Be aware that some servers treat URLs as case-sensitive. Ensure your redirects account for both cases if necessary.
Conflicting Rules: If you're using both a plugin and .htaccess for redirects, they can conflict. It's generally best to choose one method and stick to it for full site redirects.
As a note, if you’re having issues that persist, contact your web host or hire a developer.