When you add htaccess redirects to your Apache server, the number after the word "Redirect" is not just a label. It tells browsers and search engines whether a URL move is permanent or temporary, and getting that choice wrong can quietly tank your SEO or break user-facing flows. The short version: use a 301 when a page has moved for good, and a 302 when the move is short-term or conditional.
Content Table
What Is an .htaccess Redirect
An
.htaccess
file is a per-directory configuration file that Apache reads on every request. It lets you control redirects, rewrite URLs, add security headers, set caching rules, and more, all without touching your main server configuration. Redirects inside
.htaccess
intercept a request for one URL and send the visitor (and any search engine crawling the page) to a different URL instead.
Apache supports two modules for redirects: the simpler
mod_alias
(which gives you the plain
Redirect
directive) and the more powerful
mod_rewrite
(which gives you
RewriteRule
). Both can produce 301 and 302 responses. Which module you use depends on how complex the matching logic needs to be.
.htaccess
rules work on Apache HTTP Server. They have no effect on Nginx, Caddy, or other web servers. If your host runs Nginx, you will need to edit your
nginx.conf
or a server block file instead.
301 Permanent Redirect
A 301 redirect tells the browser and every search engine crawler that the original URL no longer exists and the new URL is its permanent replacement. Once a crawler sees a 301, it updates its index to point to the destination URL and transfers the original page's ranking signals (often called "link equity") to the new address. Browsers also cache 301 responses aggressively, so repeat visitors skip the redirect entirely after the first hit.
Use a 301 when:
-
You rename or restructure a URL permanently (e.g.,
/old-productbecomes/new-product). - You migrate a site from HTTP to HTTPS.
-
You switch domains (e.g.,
example.comtomybrand.com). - You consolidate duplicate content onto a single canonical URL.
- You remove a trailing slash or enforce a consistent URL format site-wide.
302 Temporary Redirect
A 302 redirect (technically "Found" in HTTP/1.1) tells the browser that the original URL still exists but the visitor should go somewhere else for now. Search engines do not transfer ranking signals from the original URL to the destination when they see a 302. They keep indexing the original URL and treat the destination as a separate page.
Use a 302 when:
- You are running an A/B test and want to split traffic between two URLs temporarily.
- A page is under maintenance and you are pointing visitors to a holding page.
-
You are doing a limited-time promotional campaign (e.g.,
/saleroutes to/summer-sale-2025for a few weeks). - You want to test a new URL structure before committing to a permanent change.
- A user is being sent to a login page because they are not authenticated (the original URL should remain their destination after login).
.htaccess
, 302 is fine, but if you redirect form submissions, 307 is safer.
301 vs 302 Side by Side
| Property | 301 Permanent | 302 Temporary |
|---|---|---|
| HTTP status code | 301 Moved Permanently | 302 Found |
| Browser caching | Aggressively cached | Not cached by default |
| SEO link equity transfer | Yes, full transfer | No transfer |
| Original URL indexed | Replaced by new URL | Kept in index |
| Reversible easily | Difficult (cached) | Yes |
| Typical use case | Site migration, URL rename | A/B tests, maintenance pages |
.htaccess Redirect Syntax and Examples
The simplest way to add a redirect in
.htaccess
is with the
Redirect
directive from
mod_alias
. The syntax is:
Redirect [status] [old-path] [new-URL]
A basic 301 redirect for a renamed page:
# 301 - Permanent redirect
Redirect 301 /old-page /new-page
# You can also use the keyword "permanent" instead of 301
Redirect permanent /old-page /new-page
A 302 temporary redirect:
# 302 - Temporary redirect
Redirect 302 /sale /summer-sale-2025
# Or use the keyword "temp"
Redirect temp /sale /summer-sale-2025
Redirecting an entire old domain to a new one (useful after a domain migration):
# Redirect all traffic from old domain to new domain root
Redirect 301 / https://www.newdomain.com/
Forcing HTTPS with a 301 (redirect all HTTP requests to HTTPS):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Using Apache Rewrite Rules for Redirects
Apache rewrite rules
(via
mod_rewrite
) give you pattern matching with regular expressions, so you can redirect entire groups of URLs based on conditions rather than listing them one by one. The
RewriteRule
directive is more flexible than
Redirect
, but it requires enabling the rewrite engine first.
The basic structure of a rewrite-based redirect:
RewriteEngine On
# Optional condition (e.g., only apply if not already HTTPS)
RewriteCond %{HTTPS} off
# Rule: match any URL, redirect to HTTPS equivalent with 301
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The flags at the end of a
RewriteRule
control its behavior:
-
[R=301]: Issue a 301 redirect to the browser. -
[R=302]: Issue a 302 redirect. -
[L]: Stop processing further rules after this one matches. -
[R=301,L]: The most common combination for permanent redirects.
A practical example: redirect all URLs under
/blog/old-category/
to
/articles/
permanently:
RewriteEngine On
RewriteRule ^blog/old-category/(.*)$ /articles/$1 [R=301,L]
The
$1
captures whatever comes after
/old-category/
and appends it to the new path, so
/blog/old-category/post-title
becomes
/articles/post-title
. This is much cleaner than writing one
Redirect
line per post.
You can read the full specification for
mod_rewrite
in the
official Apache mod_rewrite documentation
. The HTTP status code definitions for 301 and 302 are specified in
RFC 9110, Section 15.4
.
If you prefer to build these rules visually without memorizing directive syntax, the
htaccess generator
on this site lets you toggle redirect rules, set source and destination URLs, and download a ready-to-deploy
.htaccess
file without writing a single line manually.
Common Redirect Mistakes to Avoid
Using 302 when you mean 301. This is the most common error. Developers add a 302 "just to test" and forget to change it. Search engines keep indexing the original URL, and the new page never picks up ranking signals. If the move is permanent, use 301 from day one.
Redirect chains. A chain happens when URL A redirects to URL B, which redirects to URL C. Each hop adds latency and dilutes SEO signals. Audit your redirects periodically and point A directly to C.
Redirect loops.
URL A redirects to URL B, which redirects back to URL A. Apache will hit the loop limit and return a 500 error. This often happens when an HTTPS rewrite rule does not check whether HTTPS is already active (
RewriteCond %{HTTPS} off
prevents this).
Forgetting the
RewriteEngine On
line.
Every
.htaccess
file that uses
mod_rewrite
must declare
RewriteEngine On
. Without it, all
RewriteRule
and
RewriteCond
directives are silently ignored.
Deploying untested rules to production. A malformed redirect can take down your entire site. Always test on a staging environment first. Google's Search Console URL Inspection tool is useful for checking how Googlebot sees a redirect after you deploy.
If you work with config-like files and want to understand how structured formats compare, the post on YAML vs JSON for config files is a useful companion read for anyone managing server and application configuration together.
Build your htaccess redirects without memorizing syntax
Our .htaccess Generator lets you configure 301 and 302 redirects, rewrite rules, and security headers through a visual interface. Toggle the rules you need, set your source and destination URLs, and download a clean, ready-to-deploy
.htaccess
file in seconds.
Generate Your .htaccess File →
Google has confirmed that 301 redirects do pass PageRank, but the transfer is not guaranteed to be exactly 100%. Historically, there was a small loss, and Google's John Mueller has indicated that some signal loss can still occur. In practice, a clean 301 from a well-established URL to a relevant destination transfers the vast majority of its ranking value, making it far better than leaving a broken page or using a 302.
Yes. You can stack as many
Redirect
directives or
RewriteRule
blocks as you need. Apache processes them in order from top to bottom. Just be careful about overlapping patterns that could match the same URL and create a chain or conflict. Using the
[L]
flag on rewrite rules stops further processing once a match is found, which prevents unintended rule stacking.
In Chrome, open DevTools (F12), go to the Network tab, check "Disable cache," and reload the page. You can also clear the browser cache manually via Settings. In Firefox, hold Shift while clicking Reload to bypass cache for that request. For thorough testing, use a private or incognito window, which starts with a clean cache state and will not have stored the old 301 destination.
The
Redirect
directive (from
mod_alias
) does simple string matching on exact paths. It is easy to read and works well for one-to-one URL moves.
RewriteRule
(from
mod_rewrite
) uses regular expressions and supports conditional logic via
RewriteCond
, making it suitable for pattern-based redirects like moving an entire directory tree or enforcing HTTPS across all URLs at once.
Most shared hosting providers run Apache and allow
.htaccess
files by default, so redirects typically work out of the box. The main exception is if the host has disabled
AllowOverride
in its Apache configuration, which prevents
.htaccess
from being read at all. Check with your hosting provider if rules appear to have no effect. For
mod_rewrite
rules specifically, the module must also be enabled on the server.
There is a small overhead because Apache reads the
.htaccess
file on every request to that directory. For high-traffic sites, Apache's official recommendation is to move rules into the main
httpd.conf
or a virtual host block instead, since those are loaded once at startup. For most small to medium sites, the difference is negligible. Redirect chains add more measurable latency than the file-read overhead itself.