How to Redirect Your Entire Website to a New Domain

Moving your website to a new domain requires proper 301 redirects. These redirects make sure users reach your new URLs. They also preserve your SEO rankings.

Key Highlights
  • Use 301 redirects for all URLs
  • Preserves 90-99% of SEO rankings (Google confirmed)
  • Works with Apache (.htaccess), Nginx, WordPress
  • Full ranking transfer usually takes 4-6 weeks

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

  1. Backup your website files and database.
  2. Verify the new domain works with SSL.
  3. Test redirects on a staging site if possible.
  4. Document your URL structure.
  5. Choose low-traffic hours for implementation.

Redirect Methods

Apache (.htaccess)

  1. Access your root directory.
  2. Edit or create the .htaccess file.
  3. 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:

  1. Visit olddomain.com/any-page.
  2. 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

  1. Always use 301 redirects, not 302 (Temporary Redirect).
  2. Include both www and non-www versions.
  3. Test all major pages.
  4. Monitor for redirect loops or errors.
  5. 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.

Share on

Dark Boys Media helps you build, set up, and scale your business. We focus on customer engagement, delivering seamless experiences and measurable results.