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
- Move one page
- Move a whole folder
- HTTP to HTTPS
- Six traps
- Too many redirects
- Nothing happens, or a 500 (Debian and Ubuntu)
- Check a redirect
Redirect vs RewriteRule
Redirect (mod_alias) | RewriteRule (mod_rewrite) | |
|---|---|---|
| On by default (Debian 12) | Yes | No, run sudo a2enmod rewrite |
| What it matches | A path and everything under it, whole path segments only | A regex you write |
| With no code | 302 | [R] is a 302 |
| Query string | Kept | Kept, unless the target has its own ? |
| Conditions (HTTPS, host) | No | Yes, with RewriteCond |
| Best for | Single pages, moved folders | HTTP 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
Redirectis a prefix match.Redirect 301 /old-page ...also moved/old-page/sub. It matches whole path segments only, so/old-pagefoowas left alone. UseRedirectMatchor aRewriteRulewith^...$for one exact page.- No code means 302.
Redirect /old-page ...andRewriteRule ... [R,L]both sent302 Found, a temporary redirect. Write301(orpermanent, which gave the same301) and[R=301,L]. - 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.Redirectuses/old-pagein both. - The first
Redirectwins. WithRedirect 301 /docs ...manualaboveRedirect 301 /docs/old ...special,/docs/oldwent to/manual/oldand the second line never ran. Put the more specific path first. - Mixing both in one
.htaccess: RewriteRule wins. With aRewriteRuleand aRedirectfor the same page, theRewriteRulewon whichever came first in the file. Pick one module per job so you don't have to remember this. - A
?in the target replaces the query string.RewriteRule ^old-page$ https://example.com/new-page?from=old [R=301,L]sent?from=oldand dropped the visitor's?x=1. AddQSAto keep both (?from=old&x=1). A bare?at the end, or theQSDflag, 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:
Redirect 301 / http://example.com/in the site's own virtual host./matches every path, including the one it redirects to.RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]withoutRewriteCond %{HTTPS} off. On the HTTPS site it redirects HTTPS to itself, forever.
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:
- The
.htaccessfile is ignored. Debian'sapache2.confsetsAllowOverride Nonefor/var/www, so the generator'sRedirectline did nothing:/old-pagestayed a404, with no error anywhere. After changing it toAllowOverride Alland restarting, the same file gave the301. In your own virtual host you can put the redirect lines there directly instead. - A
RewriteRulefile gives a 500 on every page. mod_rewrite is off by default, and the error log saidInvalid command 'RewriteEngine'. Aftersudo a2enmod rewriteand a restart, the HTTPS redirect worked.Redirectneeds no extra module: mod_alias was already on. More on this error in Apache “Invalid command”.
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