How to Create a Temporary 302 Redirect via htaccess

htaccess & Redirects | Updated March 2026

A 302 redirect sends visitors (and search engines) to a different URL temporarily. Unlike a 301 (permanent), a 302 tells search engines to keep the original URL indexed because the redirect is not permanent. This guide covers how to set up 302 redirects in .htaccess, when to use them versus 301s, and common patterns.

01. When to Use a 302 vs 301

Temporary

302 Redirect

  • Page is temporarily moved
  • Search engines keep the old URL indexed
  • Link equity stays with the original URL
  • Use for: maintenance pages, A/B testing, seasonal content, temporary promotions
Warning

Using a 302 when you mean 301 (or vice versa) has real SEO consequences. If a page has permanently moved, use 301. Google will eventually treat a long-running 302 as a 301, but it takes longer and you may lose ranking signals during the transition.

02. Basic 302 Redirect

The simplest way to create a 302 redirect is with Apache's Redirect directive. Add this to your .htaccess file:

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

The first argument is the status code (302), the second is the old path (relative to the document root), and the third is the full destination URL.

Redirect an Entire Directory

Redirect 302 /old-directory/ https://yourdomain.com/new-directory/

This redirects everything under /old-directory/ to the corresponding path under /new-directory/. So /old-directory/page.html goes to /new-directory/page.html.

Redirect to an External Site

Redirect 302 /promo https://external-site.com/special-offer

Using RewriteRule (More Control)

For more complex redirects, use mod_rewrite:

RewriteEngine On
RewriteRule ^old-page\.html$ /new-page.html [R=302,L]

The [R=302,L] flags mean: R=302 sets the redirect type, L means stop processing rules after this match.

03. Common Redirect Patterns

Redirect Homepage Temporarily (Maintenance Mode)

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /maintenance.html [R=302,L]
Tip

If you want to exclude your own IP so you can still see the real site while visitors see the maintenance page, add a condition before the rule:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.89$
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ /maintenance.html [R=302,L]

Replace 123.45.67.89 with your actual IP address.

Redirect All HTTP to HTTPS (Temporary)

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

Change to [R=301,L] once you've confirmed everything works over HTTPS. See our Mixed Content guide for the full HTTPS transition process.

Redirect a Single Page to a Different Domain

Redirect 302 /special-offer https://shop.yourdomain.com/promo

Redirect Based on Query String

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=5$
RewriteRule ^products\.php$ /products/widget/ [R=302,L]

This redirects products.php?id=5 to /products/widget/.

04. Regex-Based Redirects

RedirectMatch lets you use regular expressions for more flexible pattern matching:

Redirect All .php Pages to .html Equivalents

RedirectMatch 302 ^/(.+)\.php$ https://yourdomain.com/$1.html

Redirect an Entire Subdirectory to Root

RedirectMatch 302 ^/blog/(.*)$ https://yourdomain.com/$1

Redirect URLs Containing a Keyword

RedirectMatch 302 ^/.*old-product.*$ https://yourdomain.com/new-product
Note

For a deeper dive into .htaccess syntax, regex patterns, and advanced rewrite rules, see our Complete Guide to .htaccess on Apache.

05. Testing Your Redirects

Always test redirects before assuming they work. Here's how:

Using curl

curl -sI https://yourdomain.com/old-page.html | head -5

You should see:

HTTP/1.1 302 Found
Location: https://yourdomain.com/new-page.html

If you see 301 Moved Permanently instead of 302 Found, check your .htaccess for a conflicting 301 rule.

Using Browser Dev Tools

Open your browser's Developer Tools (F12), go to the Network tab, visit the old URL, and look at the first request. The Status column should show 302, and the Response Headers should include a Location header pointing to the new URL.

Warning

Browsers cache 301 redirects aggressively. If you changed a redirect from 301 to 302, your browser may still follow the cached 301. Test in an incognito/private window or clear your browser cache.

06. Troubleshooting

Redirect Loop (ERR_TOO_MANY_REDIRECTS)

This means the redirect is pointing to a URL that itself redirects back. Common causes:

  • HTTP/HTTPS conflict - you're redirecting to an HTTP URL that then gets forced to HTTPS, which then matches your redirect rule again. Make sure the destination URL uses https://
  • Trailing slash mismatch - /page redirects to /page/ which redirects back to /page. Be consistent with trailing slashes
  • Conflicting rules - two rules that contradict each other. Check for duplicate or overlapping rules in your .htaccess

Redirect Not Working at All

  • mod_rewrite not enabled - our servers have it enabled by default, but verify your .htaccess starts with RewriteEngine On if using RewriteRule
  • File exists at the old path - Apache serves the actual file before processing redirects. If old-page.html still exists, rename or delete it
  • .htaccess in wrong directory - the file must be in the directory that contains (or would contain) the old URL path. For site-wide redirects, use the .htaccess in public_html
  • Cached by CDN - if you use Cloudflare, purge the cache after adding redirect rules

Wrong Redirect Code (302 Instead of 301)

If you're seeing 302 but want 301 (or vice versa), simply change the number in your rule. Redirect 301 or [R=301,L] for permanent, Redirect 302 or [R=302,L] for temporary.

Need Help With Redirects?

If your redirect isn't working as expected, open a support ticket with the redirect rule you're using and what behavior you're seeing.

Open a Support Ticket

Quick Recap: 302 Redirects

If you only do 5 things from this guide, do these:

  1. Use 302 for temporary, 301 for permanent - they have different SEO implications
  2. Simplest syntax - Redirect 302 /old /new in .htaccess
  3. Test with curl - verify the response code and Location header
  4. Test in incognito - browsers cache redirects, especially 301s
  5. Check for loops - make sure the destination doesn't redirect back to the source

Last updated March 2026 · Browse all htaccess articles · See also: Complete .htaccess Guide

  • 336 Users Found This Useful

Was this answer helpful?

Related Articles

Complete Guide to htaccess on Apache

htaccess & Redirects | Updated 2026 The .htaccess file is one of the most powerful tools...

Nginx and htaccess Redirect Issues

htaccess & Redirects | Updated March 2026 If your .htaccess redirects aren't working for...

Disable error_log via htaccess

Disabling error_log Files via .htaccess   If your error_log file is growing large and...

When I Upload an htaccess File It Disappears

htaccess & Redirects | Updated March 2026 Your .htaccess file is there. You just can't...

Create a 410 Redirect for Missing Files

Creating a 410 Gone Redirect for Removed Pages   A 410 response tells search engines that a...



Save 30% on web hosting - Use coupon code Hosting30