Skip to main content

Types of Redirects

Understanding the various types of redirects is crucial for web developers, SEO specialists, and anyone involved in managing websites. Redirects play a vital role in maintaining user experience, preserving search engine rankings, and ensuring smooth navigation when content moves or changes. This page explores the most common types of redirects, including HTTP status code redirects (301, 302, 303, 307, and 308), as well as client-side redirects implemented through meta tags and JavaScript. For a more comprehensive overview of HTTP status codes, check out our HTTP Status Codes page.

Whether you're optimizing your site's structure, handling legacy URLs, or managing temporary content changes, knowing when and how to use each type of redirect is essential for effective web management.

Use our Redirect Checker tool to test different types of redirects and ensure your website's redirections are correctly implemented.

301 (Permanent Redirect)

Indicates that the requested resource has been permanently moved to a new URL.

Example Scenario:

A website has changed its domain from http://old-domain.com to http://new-domain.com.

Example Implementation:

// Apache (.htaccess)
Redirect 301 / http://new-domain.com/

// Nginx
server {
    server_name old-domain.com;
    return 301 $scheme://new-domain.com$request_uri;
}

302 (Temporary Redirect)

Indicates that the requested resource is temporarily located at a different URL.

Example Scenario:

A page is temporarily unavailable due to maintenance, so users are redirected to a maintenance page.

Example Implementation:

// PHP
header("Location: /maintenance.php", true, 302);
exit();

// JavaScript
window.location.replace("/maintenance.html");

303 (See Other)

Indicates that the response to the request can be found at a different URL using a GET method.

Example Scenario:

After a POST request (e.g., form submission), redirect the user to a confirmation page.

Example Implementation:

// Node.js with Express
app.post('/submit-form', (req, res) => {
    // Process form data
    res.redirect(303, '/confirmation');
});

307 (Temporary Redirect)

Similar to 302, but the request method and body should not be changed when reissuing the request.

Example Scenario:

Temporarily redirect POST requests to a different server while maintaining the POST method.

Example Implementation:

// Node.js with Express
app.use((req, res, next) => {
    if (req.method === 'POST' && someCondition) {
        res.redirect(307, 'https://alternative-server.com' + req.url);
    } else {
        next();
    }
});

308 (Permanent Redirect)

Similar to 301, but the request method and body should not be changed when reissuing the request.

Example Scenario:

Permanently redirect all traffic from HTTP to HTTPS while preserving the request method.

Example Implementation:

// Nginx
server {
    listen 80;
    server_name example.com;
    return 308 https://$server_name$request_uri;
}

Meta Refresh

A client-side redirect implemented using HTML meta tags.

Example Scenario:

Redirect users after a set time period, often used for "You will be redirected in X seconds" messages.

Example Implementation:

<meta http-equiv="refresh" content="5;url=https://example.com">

JavaScript Redirect

A client-side redirect implemented using JavaScript.

Example Scenario:

Redirect users based on certain conditions or user interactions.

Example Implementation:

// Immediate redirect
window.location.href = "https://example.com";

// Delayed redirect
setTimeout(() => {
    window.location.href = "https://example.com";
}, 5000); // 5 seconds delay