A page moved, a URL structure changed, or an old domain needs to point somewhere new — and
now every link, bookmark, and search result pointing at the old address returns a 404. On
an Apache server, the fix lives in one small, easily misunderstood file: .htaccess.
The directives themselves are short, but a single stray character can take a whole directory offline or quietly send both users and search engines in circles. This guide walks through what Apache redirects actually do, how to write them correctly, and the mistakes that turn a one-line fix into a server error.
Apache redirects are set up in a site's .htaccess file using directives like
Redirect, RedirectMatch, or mod_rewrite rules. A
301 redirect (permanent) is used for pages that have moved for good, while a 302
(temporary) is used for short-term changes. Rules are placed near the top of
.htaccess, and each one should be tested with the actual old URL to confirm
it lands on the correct new page without creating a loop.
What is an Apache redirect?
An Apache redirect is a server-level instruction that tells a browser or crawler requesting one URL to go fetch a different URL instead. It happens before the page ever renders — the server responds with a status code and a new location, and the client follows it automatically.
- It lives in .htaccess (or the main config). On shared hosting, redirect rules almost always go in the
.htaccessfile at the site's root; on servers you control directly, the same directives can go in the mainhttpd.confor a virtual host block. - It's driven by two Apache modules. Simple, literal redirects use
mod_alias(Redirect,RedirectMatch); pattern-based or conditional redirects usemod_rewrite(RewriteRule,RewriteCond). - The status code carries meaning. A 301 tells search engines the old URL is permanently gone and to transfer its ranking signals; a 302 says the move is temporary and the original URL should stay indexed.
- It affects every visitor, not just search engines. Anyone with an old bookmark, an old link in an email, or a stale search result gets forwarded automatically instead of hitting a dead page.
The mechanism is simple. What trips people up is precision — matching the exact old path, avoiding accidental loops, and choosing the right directive for the job.
Why redirects matter for SEO and users
A missing or incorrect redirect has consequences well beyond a single broken link:
- Preserves rankings after a URL change. A correct 301 consolidates backlinks and ranking history onto the new URL instead of starting the new page from zero.
- Stops 404s from piling up. Every unredirected old URL that's still linked externally is a dead end for both users and crawlers, wasting crawl budget on pages that no longer exist.
- Protects existing traffic during a migration. Domain moves, HTTPS migrations, and URL restructuring all rely on redirects to keep existing search visibility intact instead of resetting it.
- Keeps external links useful. Old press mentions, backlinks, and bookmarks continue working years after the original page has been restructured or removed.
Step-by-step: writing a redirect in .htaccess
- Locate or create the .htaccess file. It sits in the root directory of the site and may be hidden by default — enable "show hidden files" in your FTP client or file manager if it isn't visible.
-
Back up the existing file before editing. A single syntax error in
.htaccesscan take the entire site down, so keep a copy you can restore from. - Choose the right status code. Use 301 for a permanent move, 302 for a temporary one — this decision affects how search engines treat the change, not just where users land.
-
Write a single-page redirect with Redirect.
# Old page to new page, permanent
Redirect 301 /old-page.html /new-page.html -
Write a pattern-based redirect with RedirectMatch when needed.
# Everything under /old-folder/ to /new-folder/
RedirectMatch 301 ^/old-folder/(.*)$ /new-folder/$1 -
Place redirect rules near the top of the file. Rules are evaluated top to bottom, so putting them before any
RewriteEngineblock prevents conflicts with other rewrite logic further down. - Test the old URL directly. Load the exact old address in a browser and confirm it lands on the correct new page with a single redirect, not a chain of several.
- Check for loops and chains. Use a redirect-checker tool or your browser's network tab to confirm the old URL doesn't bounce through multiple hops before reaching its destination.
Common mistakes that break redirects
1. Creating a redirect loop
If the destination URL matches the source pattern, the rule redirects to itself indefinitely. Browsers catch this and show an error instead of an infinite loop, but the page becomes permanently unreachable until the rule is fixed.
2. Using 302 for a permanent change
A temporary status code on a page that isn't coming back tells search engines to keep the old URL indexed and hold off transferring ranking signals, which stalls the new page's performance for no reason.
3. Forgetting to escape special characters in RedirectMatch
RedirectMatch patterns are regular expressions — an unescaped dot, question mark, or parenthesis can match far more (or less) than intended, sending unrelated URLs to the wrong place.
4. Stacking too many redirect chains
Redirecting A to B, then later B to C without updating the original rule, creates a chain that adds latency and can eventually stop passing SEO value the way a single-hop redirect does.
5. Placing rules after a RewriteEngine block
Order matters in .htaccess — a mod_rewrite rule earlier in the file can catch
a request before it ever reaches a Redirect directive placed further down, so the intended
redirect never fires.
Real-world examples
How different situations translate into specific Apache redirect rules:
In each case, the directive is short — the work is in matching the exact old pattern and picking the status code that matches how permanent the change really is.
Redirect methods compared
A look at the main ways to redirect URLs on an Apache server, and where each one fits best.
| Method | Setup effort | Flexibility | Best for |
|---|---|---|---|
| Redirect (mod_alias) | Low, one line | Exact URLs only | Single moved pages |
| RedirectMatch (mod_alias) | Moderate, needs regex | Pattern-based | Whole folders or URL patterns |
| RewriteRule (mod_rewrite) | High, needs conditions | Fully conditional | HTTPS forcing, complex logic |
| Redirect generator tool | Low, form-based | Covers common cases | Non-developers, quick fixes |
Generate your redirect rule right now — free
The Rebrixe .htaccess Redirect Generator builds clean, correctly escaped redirect rules for
single pages, folders, and HTTPS forcing. No account, no watermark — just enter your URLs
and copy the result into your .htaccess file.
Frequently asked questions
RedirectMatch 301 ^/old-folder/(.*)$ /new-folder/$1 can forward every URL
under one folder to the equivalent path under another.