301 redirect: when you need it and how to redirect without losing traffic

We explain how permanent redirects differ from temporary ones, when you need them and how to configure them in .htaccess, Nginx or PHP.

48Views

301 redirect: when you need it and how to redirect without losing traffic

A 301 redirect permanently redirects an old page URL to a new one. The server returns the 301 Moved Permanently status code, the browser immediately opens the new page, and Google recognizes the move as permanent. Over time, Google displays the new URL instead of the old one in search results. Use this redirect when a page has moved permanently: the domain has changed, the URL structure is different or a product has been replaced. Below, we explain when you need a 301 redirect, how it differs from other status codes and how to configure it.

When you need a permanent redirect

Use a permanent redirect whenever an old URL stops working but still has incoming links or appears in search results. Common situations include:

  • moving to a new domain, for example, after rebranding;
  • switching from HTTP to HTTPS;
  • choosing the preferred website version: with or without www, with or without a trailing slash;
  • changing the URL structure after a redesign or CMS migration, when /index.php?id=25 becomes /uslugi/remont/;
  • merging two similar articles into one;
  • replacing a discontinued product with a new model or a relevant product category.

If you delete a page and have no replacement, you do not need a redirect. Returning a 404 or 410 status code is more appropriate. Redirecting every deleted page to the homepage is a bad idea. Google may treat these redirects as soft 404 errors, and visitors looking for a specific product will simply leave.

How a 301 differs from a 302 and other status codes

Google's documentation divides redirects into permanent and temporary types. A permanent redirect tells the search engine to display the new URL. A temporary redirect keeps the old URL in search results.

TypeHow Google interprets itWhen to use it
301, 308Permanent, the new URL becomes the primary addressPermanent page or website migration
302, 303, 307Temporary, the original URL usually remains in search resultsWeek-long promotion, website maintenance, A/B testing
Meta refresh with a 0-second delayPermanentWhen server settings are inaccessible
Meta refresh with a delayTemporaryAlmost never
JavaScript redirectGoogle may miss it if the page fails to renderOnly when other methods are unavailable

The difference between 301 and 308 is technical: with a 308, the browser must repeat the request using the same method, such as POST. A 301 is more commonly used for regular website pages. The main rule in Google's documentation is to use a permanent redirect only when you are sure you will not reverse it.

What happens in search results after a redirect

Google does not forget the old URL immediately. According to Google's documentation, the search engine keeps both URLs after a redirect: one becomes canonical, while the other is treated as an alternative name for the same page and may still appear in search results for some time. This is normal and nothing to worry about.

Sometimes a rel="canonical" tag is more appropriate than a redirect. The difference is simple: a redirect sends both visitors and crawlers to the new page, while a canonical tag keeps both pages accessible and tells Google which one to display in search results. For example, the same product page may be accessible from two categories. Visitors can stay on the page they opened, so a canonical tag is more appropriate than a redirect.

How to set up a 301 redirect

The method depends on your server and CMS. Server-side redirects work best because they take effect before the page loads and are understood by both browsers and crawlers.

Apache and the .htaccess file

If your website runs on Apache, add redirect rules to the .htaccess file in the website's root directory. Here is a simple example for a single page:

  • Redirect 301 /old-page/ https://example.com/new-page/

Use the mod_rewrite module for URL patterns and conditions. For example, here is how to redirect an entire website to HTTPS:

  • RewriteEngine On
  • RewriteCond %{HTTPS} off
  • RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Nginx

Add a location block to the server configuration with the return 301 directive and the new URL. These settings are usually accessible to the server administrator or through the hosting control panel.

PHP

If you cannot access the server configuration, you can issue a redirect from your code using the header() function with the Location header and a 301 status code, then stop script execution.

CMS

Many content management systems have a redirect module or plugin that lets you enter old and new URL pairs into a table without editing files. This is convenient when you have dozens of redirects managed by a content manager.

Make a backup of your .htaccess file before editing it. A single syntax error can take the entire website offline with a 500 error.

Website migration: how to avoid losing traffic

Changing a domain or URL structure can require hundreds of redirects. The order of operations matters.

  1. Create a URL mapping table with each old URL and its corresponding new URL. Sources of old URLs include your sitemap, Search Console reports and Google Analytics exports.
  2. Set up redirects from each old URL directly to its corresponding new URL, without intermediate steps.
  3. Update internal links, navigation menus and the sitemap so they point directly to the new URLs.
  4. When changing domains, use the Change of Address tool in Search Console. According to Google's documentation, this tool is unnecessary when switching to HTTPS, choosing between www and non-www versions or changing URL paths within the same domain.
  5. Monitor Search Console reports for several weeks after the migration.

Google recommends keeping redirects in place for as long as possible, generally for at least one year. If you remove them after a month, old links from other websites and visitors' bookmarks will lead to nonexistent pages.

Common mistakes

  • Redirect chains. URL A redirects to B, B to C, and C to D. According to Google, Googlebot follows up to 10 redirects, but Google recommends keeping chains short, ideally no more than three redirects. Each old URL should point directly to its final destination.
  • Redirect loops. A page redirects back to itself through other URLs, causing the browser to display an error.
  • Using 302 instead of 301. You need a 301 redirect, but many plugins use a temporary status code by default. During a migration, Google will keep the old URLs in search results.
  • Redirecting to an error page. The new URL returns a 404 status code, defeating the purpose of the redirect.
  • Redirecting everything to the homepage. Convenient for the developer, but useless to visitors and search engines.

How to check a redirect

The easiest way to check whether a 301 redirect works is to open your browser's developer tools (F12), select the Network tab and load the old URL. The first row will show the response status code: 301 or 302. Running the curl -I command with the page URL gives you the same result. The URL Inspection tool in Search Console shows which URL Google considers canonical. To check redirects in bulk after a migration, use website crawlers that scan a list of URLs and display their response status codes in a table.

How WID7 can help

If you are moving to a new domain or your traffic has dropped after a redesign, request a website audit from UAH 3,500. We check redirects, redirect chains, 404 errors, your sitemap and internal links, then provide a table of recommended fixes.

If your website needs rebuilding, take a look at our website development services. We build new websites using our own WID CMS, and it is best to discuss the list of old URLs requiring redirects before development begins. For a detailed review of indexing and search rankings, request an SEO audit, also from UAH 3,500.

Rate this article

Other articles

loading