Go back

301 and 302 Redirects: What They Are and How to Use Them Correctly

301 and 302 redirects are fundamental elements in website management, especially when we make changes to the structure or need to move content. When implemented correctly, they keep the user experience smooth and preserve the SEO value of our pages. In this article, we will explore in depth what redirects are, their different types, and how to implement them properly.

What are HTTP redirects?

HTTP redirects are server responses that tell the browser to look for the requested resource at a different location. When a user tries to access a specific URL, the server can respond with a redirect status code, along with the new location where the content is found.

These redirects work as «digital signposts» that guide both users and search engines to the correct location when:

  • The site’s URL structure has changed
  • A page has been moved to another location
  • Two pages have been merged
  • A page has been deleted and you want to direct users to an alternative
  • You need to redirect from a non-www version to www (or vice versa)
  • Switching from HTTP to HTTPS

301 and 302 redirects are part of the HTTP status codes, which are standardized numerical responses that web servers send to browsers. Redirect codes belong to the 3xx response group.

301 and 302 Redirects: Types and When to Use Them

There are several types of redirects, such as 301 and 302 redirects, each with a specific purpose. Knowing the differences between them is crucial for implementing them correctly.

301 Redirect – Moved Permanently

The 301 redirect indicates that the page has been permanently moved to a new location. It is the most common and recommended for most cases.

When to use 301 redirects:

  • When you change your website’s domain
  • When consolidating similar or duplicate content
  • When permanently changing the URL structure
  • When migrating from HTTP to HTTPS
  • To standardize access to your site (redirect from www to non-www or vice versa)

Example of HTTP response code:

HTTP/1.1 301 Moved Permanently
Location: https://www.newdomain.com/new-page

301 redirects pass up to 99% of the original page’s SEO value to the new one, making them ideal for preserving ranking.

302 Redirect – Found

The 302 redirect indicates that the page has been temporarily moved to another location. The resource still exists at the original URL but is temporarily available at another URL.

When to use 302 redirects:

  • During site maintenance
  • For A/B or multivariate testing
  • When redirecting based on user location or language
  • For temporary promotions or events
  • When planning to return to the original URL in the future

Example of HTTP response code:

HTTP/1.1 302 Found
Location: https://www.yourdomain.com/temporary-page

Unlike the 301 redirect, the 302 indicates to search engines that they should keep the original URL indexed, as the change is not permanent.

303 Redirect – See Other

The 303 redirect indicates that the requested resource can be found at another URL and should be retrieved using a GET request, regardless of the method used in the original request.

When to use 303 redirects:

  • After submitting a form, to avoid accidental resubmissions
  • To separate the response of an action from the action itself
  • When you want the user to see a result but not bookmark the action’s URL

Example of HTTP response code:

HTTP/1.1 303 See Other
Location: https://www.yourdomain.com/payment-confirmation

301 htaccess

The .htaccess file is a powerful tool for implementing redirects on Apache servers. It allows you to configure redirects at the server level without needing to modify the page code.

Example of a simple 301 redirect in .htaccess:

Redirect 301 /old-page.html https://www.yourdomain.com/new-page.html

Example of a 301 redirect with regular expressions:

RewriteEngine On
RewriteRule ^products/([0-9]+)/(.*)$ /catalog/$1/$2 [R=301,L]

This code will redirect URLs like /products/123/item to /catalog/123/item.

Full domain redirect:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ https://www.newdomain.com/$1 [R=301,L]

How to create one?

There are several ways to implement redirects, depending on your web server and level of access:

1. Through .htaccess (Apache): As we saw earlier, the .htaccess file allows you to configure redirects at the server level.

2. On the Nginx server:

server {
    listen 80;
    server_name oldurl.com;
    return 301 https://newurl.com$request_uri;
}

3. Using PHP:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.newdomain.com/new-page");
exit();
?>

4. With JavaScript (not recommended for SEO):

window.location.replace("https://www.newdomain.com/new-page");

5. Meta refresh (not recommended for SEO):

<meta http-equiv="refresh" content="0;url=https://www.newdomain.com/new-page">

It is important to note that options 4 and 5 are not recommended for SEO, as they do not send the correct HTTP status code to search engines.

If you work with a cdmonhosting, you can easily configure 301 and 302 redirects through the control panel. You have options like URL redirects, which allow you to modify DNS records so that the request is sent to the final destination. You can also configure DNS redirects using A records, as long as the destination server allows it. If the destination server does not accept external domains, cdmon offers the alias to efficiently manage these types of situations.

Differences between 301 and 302 redirects

Although both redirects take users to a new location, there are significant differences between them:

Feature 301 Redirect 302 Redirect
Nature Permanent Temporary
SEO authority transfer ~99% Limited or none
Browser cache Stored Not stored permanently
Indexing Google indexes the new URL Google keeps the original URL in the index
Ideal use Permanent structural changes Temporary changes

The choice between 301 and 302 should be based primarily on whether the change is permanent or temporary. Incorrectly using a 302 redirect for a permanent change can result in the loss of SEO ranking, as search engines will not transfer the authority from the original page to the new one.

301 in WordPress

WordPress offers several ways to implement 301 redirects, from native methods to specialized plugins:

1. Via the .htaccess file:

You can edit the .htaccess file in the root of your WordPress installation. For example:

# 301 redirect for a specific page
Redirect 301 /old-page https://www.yourdomain.com/new-page

# Redirect an entire directory
RedirectMatch 301 ^/old-category/(.*)$ https://www.yourdomain.com/new-category/$1

2. Using redirection plugins:

  • Redirection: A free and popular plugin that allows you to easily manage redirects from the admin panel.
  • Yoast SEO Premium: Includes a redirect manager that automatically suggests redirects when you change permalinks.
  • All in One SEO Pack Pro: Offers similar redirection functionalities to Yoast.
  • 301 Redirects: A lightweight plugin focused exclusively on redirect management.

3. Through functions.php:

function custom_redirect() {
    if ($_SERVER['REQUEST_URI'] == '/old-page/') {
        wp_redirect('https://www.yourdomain.com/new-page/', 301);
        exit;
    }
}
add_action('template_redirect', 'custom_redirect');

The advantage of using plugins is that they provide a user-friendly interface and do not require technical knowledge of code or server access.

Impact of redirects on SEO

Redirects, when implemented correctly, can have a significant impact on SEO:

Positive aspects

  1. Preservation of page authority: 301 redirects transfer approximately 99% of the original page’s SEO value to the new one.
  2. Prevention of duplicate content: By redirecting old URLs to new ones, you avoid duplicate content issues that could dilute your ranking.
  3. Improvement of user experience: Redirects prevent users from encountering 404 error pages, reducing bounce rates.
  4. Consolidation of link signals: When multiple URLs point to the same content, redirects can consolidate these signals into a single URL.

Important considerations

  1. Loading speed: Redirects add additional loading time. Each redirect can add between 100-300ms to the loading time.
  2. Redirect chains: Avoid redirect chains (A → B → C → D), as they can negatively affect both SEO and user experience. Google recommends having no more than 3-5 redirects in a chain.
  3. Monitoring: It is important to monitor redirects to ensure they work correctly and there are no broken links.
  4. Updating internal links: Although redirects work, it is better to update internal links to point directly to the new URLs.

Common errors when using redirects and how to avoid them

Below are some common errors and how to avoid them:

1. Using 302 redirects for permanent changes

Problem: 302 redirects do not effectively transfer SEO authority.

Solution: Use 301 redirects for all permanent URL changes.

2. Redirect chains

Problem: Multiple redirects in sequence slow down loading and can cause crawling issues.

Solution: Simplify redirects to go directly from the original URL to the final one. Periodically review your redirects to identify and correct chains.

3. Redirecting to irrelevant pages

Problem: Redirecting to unrelated content confuses users and search engines.

Solution: Always redirect to thematically similar or relevant content. If the original page no longer exists, redirect to the closest alternative in terms of content.

Problem: Keeping internal links to redirected URLs creates unnecessary redirects.

Solution: Systematically update all internal links to point directly to the new URLs.

5. Circular redirects

Problem: Redirects that form a loop (A → B → A) generate errors and are harmful.

Solution: Test all redirects before implementing them in production. Use tools like Screaming Frog or Redirect Checker to detect circular redirects.

6. Not redirecting at the page level

Problem: Redirecting all old pages to the homepage instead of the corresponding new pages.

Solution: Create specific page-to-page redirects whenever possible.

7. Not monitoring after implementation

Problem: Not detecting issues with implemented redirects.

Solution: Use tools like Google Search Console to monitor crawl errors and redirect issues.

8. Implementing temporary redirects for permanent changes

Problem: Temporary redirects like JavaScript or meta refresh do not pass SEO value.

Solution: Always implement server-level redirects (301/302) instead of client-side solutions.

301 and 302 redirects are powerful tools in the arsenal of any web administrator or SEO specialist. When implemented correctly, they ensure a smooth transition during structural changes, preserve accumulated SEO value, and maintain a positive user experience. The key is to choose the right type of redirect for each situation and follow best practices in its implementation.

We have solutions for everyone