Apache Redirects: A Practical .htaccess Guide

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.

Quick Answer

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.

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:

📊 Quick stat Most redirect-related ranking drops trace back to using a 302 for what was actually a permanent change — the wrong status code, not a missing rule, is the more common failure.

Step-by-step: writing a redirect in .htaccess

  1. 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.
  2. Back up the existing file before editing. A single syntax error in .htaccess can take the entire site down, so keep a copy you can restore from.
  3. 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.
  4. Write a single-page redirect with Redirect.
    # Old page to new page, permanent
    Redirect 301 /old-page.html /new-page.html
  5. Write a pattern-based redirect with RedirectMatch when needed.
    # Everything under /old-folder/ to /new-folder/
    RedirectMatch 301 ^/old-folder/(.*)$ /new-folder/$1
  6. Place redirect rules near the top of the file. Rules are evaluated top to bottom, so putting them before any RewriteEngine block prevents conflicts with other rewrite logic further down.
  7. 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.
  8. 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.
Try the Rebrixe .htaccess Redirect Generator — free Enter your old and new URLs, pick 301 or 302, get a ready-to-paste rule.
Generate Redirect Rule →

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.

💡 Pro tip After editing .htaccess, always reload the old URL in a private/incognito window — browsers aggressively cache 301 redirects, so a fix can look broken simply because the old result is still cached locally.

Real-world examples

How different situations translate into specific Apache redirect rules:

Blog restructure
Single-page redirect
301, one line
An old post URL moves to a new slug; a single Redirect 301 line preserves its backlinks.
Category rename
Folder-wide redirect
RedirectMatch
An entire /shop-old/ folder maps to /shop/ using one regex-based rule instead of one per product.
HTTPS migration
Protocol-wide redirect
mod_rewrite
A RewriteCond checks for HTTP and forces every request onto the HTTPS version of the same URL.
Domain change
Sitewide redirect
301, root-level
Every request to the old domain forwards to the equivalent path on the new one, preserving rankings during the move.

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.

Free .htaccess Redirect Generator Enter old and new URLs, choose 301 or 302, copy the rule.
Open Redirect Generator →

Frequently asked questions

A 301 tells browsers and search engines the move is permanent and passes ranking signals to the new URL. A 302 signals a temporary move and search engines generally keep indexing the original URL instead of the new one.
A single old-URL-to-new-URL redirect only needs the Redirect or RedirectMatch directive from mod_alias. mod_rewrite is only necessary for pattern-based logic, like conditional redirects or rewriting query strings.
Redirect and RedirectMatch rules go near the top of the .htaccess file in the site's root directory, before any RewriteEngine block, so they run before other rewrite logic is evaluated.
A 500 error from a redirect rule usually means a syntax mistake, an unescaped special character in a RedirectMatch pattern, or a redirect loop where the destination URL matches the source pattern and redirects to itself.
Yes. RedirectMatch accepts a regular expression, so a single rule like RedirectMatch 301 ^/old-folder/(.*)$ /new-folder/$1 can forward every URL under one folder to the equivalent path under another.
A correct 301 redirect resolves duplicate URLs and consolidates most ranking signals to the new page, but it does not guarantee the new URL will rank identically, and search engines can take time to fully process the change.

Generate your .htaccess redirect in seconds

The Rebrixe .htaccess Redirect Generator builds clean, correctly escaped redirect rules — no account, no watermark, just a ready-to-paste block for your .htaccess file.

Launch the Redirect Generator →
← Back to blogs