Jump to content
KUHM

301 Redirect from One Site to Another (Old URL to New URL)

Posted on - Updated

301 Redirect from One Site to Another (Old URL to New URL)

A 301 redirect from the old URL to the new URL tells browsers and search engines that an address has changed permanently. I often redirect an entire site to another one, either because the domain name is changing or to "recover" the weight of an old site: here is what to set up so that every page lands in the right place.

Why a 301 and not a simple temporary redirect

A 301 redirect signals a permanent move. Google then gradually replaces the old address with the new one in its index and carries over to the new page the signals accumulated by the old one, notably the links pointing to it. A temporary redirect says the opposite: the old address remains the reference, and the new one does not inherit from it as clearly. For a domain change, the 301 is therefore always the one to use.

The second point that matters is page-to-page matching. Redirecting all the old addresses to the new site's homepage alone loses most of the benefit: a user arriving from a link to an article does not find that article, and Google often treats these redirects as pages not found.

The htaccess rule on Apache: site1.com to site-deux.com

You work on the .htaccess file placed at the root of site1.com, with Apache's rewrite module enabled:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?exemple1\.com$ [NC]
RewriteRule ^(.*)$ https://www.exemple2.com/$1 [R=301,L]

The condition targets the old domain, with or without www, regardless of case. The rule captures the requested path and appends it after the new domain thanks to $1: exemple1.com/contact/ goes to www.exemple2.com/contact/, and not to the homepage. URL parameters are passed along automatically by Apache. If the address structure also changes between the two sites, you need to add specific rules for the renamed pages before this general rule.

When a single site responds under several extensions, the principle is the same: 301 redirects between several TLDs of the same site prevent the .com version and the .fr version from competing with each other.

The same move on an Nginx server

An Nginx server does not read .htaccess files. The redirect is declared in the server block of the old domain, and the $request_uri variable preserves the path as well as the parameters:

server {
    server_name exemple1.com www.exemple1.com;
    return 301 https://www.exemple2.com$request_uri;
}

After reloading the configuration, a test on a few deep addresses (article, category, page with parameters) is enough to check that each one lands on its equivalent and that none goes through a chain of successive redirects.

Declaring the domain change in Search Console

Even better is to declare the address change in Search Console, Google's tool formerly called webmaster tools. The old "Site configuration" menu no longer exists: the change of address tool opens from the settings of the old domain's property, and Google requires you to be a verified owner of both properties, the old and the new.

According to the Search Console help, this tool is only for a domain change. It is not used for a switch from HTTP to HTTPS, nor for moving from the www version to the non-www version: in both cases, redirects and the canonical tag are enough.

Finally, Google recommends keeping the redirects in place for at least 180 days, and longer if users still arrive on the old site from its results. Keeping the old domain name renewed for at least a year also prevents a third party from buying it and capturing the residual traffic.

A redirect that also fixes duplicate content

The 301 redirect is not only for site moves. It also resolves internal duplicates, when the same page responds at two addresses: the classic case is a homepage reachable with and without the file name, which a rule can bring back to a single address by fixing the index.php duplicate.

About the author

Cyril KUHM

Cyril KUHM

Head of MKH, a web agency near Strasbourg, and SEO consultant since 2007. On this blog I share free, hands-on advice to help your site rank better on Google.

Get in touch

Related posts

↑