Apache Redirect 301 vs RewriteRule: which to use, tested

Updated 18 November 2026 · By Brent Alexis

Short answer: to move one page or a whole folder in Apache, use Redirect 301. It's one line, mod_alias is on by default, and it keeps the query string. Use RewriteRule when the redirect depends on something else, like HTTP vs HTTPS or the host name, or when you need a regex. Two traps catch most people: Redirect also moves everything under the path, and both send a temporary 302 unless you write the code.

Tested on the official httpd Docker image and Debian 12 (both Apache 2.4.71) with ProxyForge's own Redirect Generator output: 43 checks. How it's tested

Redirect vs RewriteRule

Redirect (mod_alias)RewriteRule (mod_rewrite)
On by default (Debian 12)YesNo, run sudo a2enmod rewrite
What it matchesA path and everything under it, whole path segments onlyA regex you write
With no code302[R] is a 302
Query stringKeptKept, unless the target has its own ?
Conditions (HTTPS, host)NoYes, with RewriteCond
Best forSingle pages, moved foldersHTTP to HTTPS, www, domain moves, patterns

That's also how ProxyForge's Redirect Generator splits the work: a single path gets a Redirect 301 line, and HTTPS, www and domain moves get RewriteRule with conditions.

Move one page

The Redirect Generator's output for one path, in .htaccess or inside your <VirtualHost>:

# mod_alias — simpler than mod_rewrite for a single fixed path
Redirect 301 /old-page https://example.com/new-page

Checked: /old-page went to https://example.com/new-page with a 301, and /old-page?x=1 kept its ?x=1. The match is case-sensitive: /Old-Page wasn't redirected.

If you want only that exact page, and nothing under it, use RedirectMatch with a regex instead. It also kept the query string:

RedirectMatch 301 ^/old-page$ https://example.com/new-page

Move a whole folder

Redirect already does this, because it matches everything under the path: with Redirect 301 /old-page https://example.com/new-page, /old-page/sub went to /new-page/sub. To rename a folder and keep the rest of the path, either works:

# mod_alias
Redirect 301 /blog https://example.com/news

# mod_rewrite (.htaccess: no leading slash in the pattern)
RewriteEngine On
RewriteRule ^blog/(.*)$ https://example.com/news/$1 [R=301,L]

Checked: the RewriteRule sent /blog/2026/post to https://example.com/news/2026/post. Reach for RewriteRule when the new path isn't a simple swap, for example when you reorder parts of it.

HTTP to HTTPS

This needs a condition, so it needs mod_rewrite. The Redirect Generator's .htaccess output:

# Let’s Encrypt renewals (certbot --webroot): a check file that exists here isn’t redirected
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Checked: http://example.com/a/b?x=1 went to https://example.com/a/b?x=1 in one hop, HTTPS requests weren't redirected again, and an existing Let's Encrypt check file was still served over plain HTTP so renewals keep working. A missing check file was redirected like any other page.

Six traps

  1. Redirect is a prefix match. Redirect 301 /old-page ... also moved /old-page/sub. It matches whole path segments only, so /old-pagefoo was left alone. Use RedirectMatch or a RewriteRule with ^...$ for one exact page.
  2. No code means 302. Redirect /old-page ... and RewriteRule ... [R,L] both sent 302 Found, a temporary redirect. Write 301 (or permanent, which gave the same 301) and [R=301,L].
  3. The leading slash. In .htaccess, RewriteRule ^old-page$ matched and ^/old-page$ never did. In a <VirtualHost> it was the other way round: only ^/old-page$ matched. Moving rules between the two means adding or removing that slash. Redirect uses /old-page in both.
  4. The first Redirect wins. With Redirect 301 /docs ...manual above Redirect 301 /docs/old ...special, /docs/old went to /manual/old and the second line never ran. Put the more specific path first.
  5. Mixing both in one .htaccess: RewriteRule wins. With a RewriteRule and a Redirect for the same page, the RewriteRule won whichever came first in the file. Pick one module per job so you don't have to remember this.
  6. A ? in the target replaces the query string. RewriteRule ^old-page$ https://example.com/new-page?from=old [R=301,L] sent ?from=old and dropped the visitor's ?x=1. Add QSA to keep both (?from=old&x=1). A bare ? at the end, or the QSD flag, drops it on purpose.

One more detail: a relative target like Redirect 301 /old-page /new-page went out as http://example.com/new-page, a full URL built from the request. Write the full https:// address yourself so visitors don't take a trip through plain HTTP.

Too many redirects

Two loops came straight out of the lab. curl gave up after 5 redirects on both, and a browser shows ERR_TOO_MANY_REDIRECTS:

The generator's HTTPS rule above has the condition, and following it ended after one redirect. If the loop only happens behind Cloudflare, it's usually the SSL/TLS mode: see ERR_TOO_MANY_REDIRECTS behind Cloudflare.

Nothing happens, or a 500 (Debian and Ubuntu)

Two things on a stock Debian 12 install change how .htaccess redirects behave:

Debian 12 was tested; Ubuntu uses the same apache2.conf layout and a2enmod tool.

Check a redirect

curl -sI http://example.com/old-page | grep -iE '^(HTTP|location)'

You want HTTP/1.1 301 Moved Permanently and the right Location. Test with curl or a private window: browsers remember a 301, so after you fix a rule your normal browser can keep showing the old redirect. For which code to use (301, 302, 307 or 308), see the Nginx redirects guide; the codes mean the same on Apache.

Generate an Apache redirect with the Redirect Generator →

How to use ProxyForge · FAQ: common errors · Guides · What's new · About