Moving your website? Learn how to redirect your entire website to a new domain. Use 301 redirects to send visitors to the right pages. This keeps your SEO rankings intact and prevents broken links.
What Are 301 Redirects?
A 301 redirect is permanent. It tells browsers and search engines that a page has moved. This prevents broken links and maintains SEO authority.
Safety Checklist
- Backup your website files and database.
- Verify the new domain works with SSL.
- Test redirects on a staging site if possible.
- Document your URL structure.
- Choose low-traffic hours for implementation.
Redirect Methods
Apache (.htaccess)
- Access your root directory.
- Edit or create the .htaccess file.
- Add this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
Result: All URLs redirect while keeping paths intact.
Nginx
server {
server_name olddomain.com www.olddomain.com;
return 301 https://newdomain.com$request_uri;
}
WordPress
Add this to functions.php:
function redirect_entire_site() {
if (!is_admin()) {
wp_redirect('https://newdomain.com' . $_SERVER['REQUEST_URI'], 301);
exit();
}
}
add_action('template_redirect', 'redirect_entire_site');
New to WordPress? Check out our guides on what is WordPress and how to build a website to get started.
How the Code Works
- RewriteEngine On: Enables URL rewriting.
- RewriteCond: Matches www and non-www versions.
- ^(.*)$ / $1: Captures and preserves full URL paths.
- [R=301,L]: Makes redirect permanent and stops further rules.
How to Test Your Redirects
Manual Test:
- Visit
olddomain.com/any-page
. - Confirm it redirects to
newdomain.com/any-page
.
Command-Line Test:
curl -I olddomain.com/page
# HTTP/1.1 301 Moved Permanently
# Location: https://newdomain.com/page
Common Problems
- Redirect loop: Ensure the new domain doesn’t redirect back.
- HTTPS issues: Install SSL on the new domain first.
- Subdomains not redirecting: Add separate rules:
RewriteCond %{HTTP_HOST} ^blog\.olddomain\.com$
RewriteRule ^(.*)$ https://newdomain.com/blog/$1 [R=301,L]
Optional Alternatives
- DNS-Level Redirect (Cloudflare): Forward all URLs.
- Registrar Forwarding: Less reliable; may not preserve URL paths.
Redirect Timeline
Immediate: Users redirected instantly.
Search Engines:
- 1–7 days: Google detects redirects.
- 2–4 weeks: Rankings start transferring.
- 4–8 weeks: Full SEO authority migrated.
- 3–6 months: Old domain removed from search results.
Migration Best Practices
- Always use 301 redirects, not 302 (Temporary Redirect).
- Include both www and non-www versions.
- Test all major pages.
- Monitor for redirect loops or errors.
- Submit Change of Address in Google Search Console.
Final Thoughts
Proper 301 redirects ensure a smooth migration. They protect SEO rankings, prevent broken links, and maintain traffic. Test carefully, monitor results, and submit changes to Google. A well-executed migration keeps your website visible and authoritative.