Learn everything about the HTTP 302 status code (Temporary Redirect). Understand its meaning, use cases, SEO impact, examples in Apache, Nginx, PHP, and how to avoid open redirect vulnerabilities.
The HTTP 302 status code is one of the most commonly encountered response codes in web development and server administration. It indicates that the requested resource has been temporarily moved to a different URI (Uniform Resource Identifier). In simpler terms, it tells the browser or client: “The page you’re looking for is somewhere else – for now.”
Table of Contents
What Is HTTP 302?
HTTP 302, also known as “Found” or “Temporary Redirect”, is part of the 3xx class of HTTP status codes used for URL redirection. When a server sends a 302 response, it provides the browser with a new location (URL) to request. The client should continue to use the original URL for future requests because the redirect is temporary.
HTTP/1.1 302 Found
Location: https://www.gowrishankar.me/new-page
In this example, the browser receives a 302 response and immediately redirects the user to https://example.com/new-page.
When to Use HTTP 302 Redirect
Developers and system administrators typically use the 302 status code in the following situations:
- Temporary Maintenance: When a page is undergoing updates but will return soon.
- A/B Testing: When redirecting users to different versions of a page temporarily.
- Geolocation-Based Routing: Redirecting users to country-specific pages based on their IP.
- Session or Login Handling: Redirecting users after login or authentication checks.
Because it’s temporary, search engines will continue to index the original URL rather than the destination, which helps preserve SEO consistency.
Difference Between HTTP 301 and HTTP 302
While both 301 and 302 perform redirects, their intent and search engine handling differ:
| Feature | HTTP 301 (Permanent) | HTTP 302 (Temporary) |
|---|---|---|
| Type | Permanent Redirect | Temporary Redirect |
| Search Engine Impact | Passes full SEO ranking to the new URL | Original URL remains indexed |
| Browser Cache | Can be cached permanently | Usually not cached or cached briefly |
| Use Case | URL change or site restructuring | Temporary redirection or testing |
Example Implementations
1. Using Apache (.htaccess)
Redirect 302 /old-page.html https://www.gowrishankar.me/new-page.html
2. Using Nginx Configuration
location /old-page {
return 302 https://www.gowrishankar.me/new-page;
}
3. Using PHP Header Function
<?php
header("Location: https://www.gowrishankar.me/new-page", true, 302);
exit();
?>
4. Using cURL Command (Testing 302 Redirection)
You can use the cURL command-line tool to test whether your server correctly issues an HTTP 302 redirect. This is useful for debugging and verifying your configuration.
Run the following command to view only the response headers:
curl -I https://www.gowrishankar.me/old-page
If the redirect is set up properly, you’ll see a response similar to:
HTTP/1.1 302 Found
Location: https://www.gowrishankar.me/new-page
To automatically follow the redirect and see the final destination, use the -L option:
curl -I -L https://www.gowrishankar.me/old-page
This command allows you to confirm that the redirection chain works correctly and ends at the intended target page. It’s an essential check for web admins and SEO specialists when validating redirect behavior.
Security Implications
Improper use of 302 redirects can introduce security and privacy issues such as:
- Open Redirect Vulnerabilities: Attackers can exploit 302 responses to redirect users to malicious sites.
- Phishing Risks: Unvalidated redirect parameters may lead users to untrusted URLs.
To mitigate these risks, always validate and sanitize redirect URLs before sending them in a response.
Best Practices for Using HTTP 302
- Use 302 only when the redirect is truly temporary.
- For permanent redirects, prefer HTTP 301 or HTTP 308.
- Ensure redirected URLs are fully qualified (absolute URLs).
- Monitor server logs for suspicious redirect activities.
SEO Considerations
From an SEO perspective, 302 redirects tell search engines that the move is temporary, so they continue to index the original page. This is ideal for temporary campaigns, A/B testing, or maintenance windows. However, if the redirection remains for a long time, consider changing it to a 301 permanent redirect to avoid confusion or ranking dilution.
Summary
The HTTP 302 status code is a powerful tool for temporary redirection, but it must be used with care. It helps maintain user experience during short-term changes without affecting SEO or permanent links. Understanding when and how to implement it properly ensures both technical efficiency and security compliance.