Home/Developer/.htaccess Redirect Generator

.htaccess Redirect Generator

Build Apache redirect rules that survive contact with a real server — prefix-match warnings, loop and chain detection, and a tester that shows which rule actually wins.

Free Browser-based No signup Copy-ready
Generator Settings
One pair per line, separated by a comma, tab or pipe. Old paths may be absolute URLs — only the path is used for matching.
Used for absolute targets and for the www rule.
Options
Generated Config ready
.htaccess

      
Rules run in order, top to bottom, and the file is re-read on every request. Put host-level rules (HTTPS, www) above page-level ones, and move the whole block into your vhost config once it is stable.

How it works

1

Pick the scenario

A URL list, HTTPS, www, a domain move, trailing slashes or a regex rewrite.

2

Check the diagnostics

Loops, duplicate sources, chains and the proxy trap are all flagged before you deploy.

3

Test, then upload

Try a URL in the tester, deploy with 302, confirm, then switch to 301.

mod_rewrite or mod_alias — and why order matters

Apache offers two independent redirect mechanisms and they do not cooperate. mod_alias gives you Redirect and RedirectMatch: simple, fast, no conditions. mod_rewrite gives you RewriteRule: regex, conditions, flags, and everything host- or query-related.

Never mix them on the same path

The two modules run in different phases, and mod_alias wins regardless of file order. A RewriteRule sitting above a Redirect for the same URL simply never fires — which looks like the rule being ignored for no reason. Pick one module per path.

The leading slash

Inside .htaccess, RewriteRule matches the path with the leading slash stripped: write ^blog/(.*)$, not ^/blog/(.*)$. In vhost config the slash is there. Copying an example from the wrong context is the single most common reason a rule silently never matches.

Order and specificity

Unlike Nginx, Apache evaluates rules strictly top to bottom and the first match with [L] stops processing. So host-level rules — HTTPS, www — belong at the top, and specific page redirects below them. Put a catch-all first and nothing after it will ever run.

Every request pays for this file

Apache re-reads .htaccess on every request, in every directory along the path. That is the price of not needing a restart. Once the rules are settled, move them into the vhost and set AllowOverride None.

Redirect /about /new matches a prefix, not a page. It also catches /about-us, /about/team and /about.html. This generator emits anchored RedirectMatch patterns instead, so a rule means what it looks like it means.

Frequently Asked Questions

View all FAQs
How do I redirect a single page in .htaccess?
Use an anchored RedirectMatch 301 ^/old-page$ https://example.com/new-page. Avoid plain Redirect for this — it matches the path as a prefix, so /old-page-2 would be caught as well.
Why is my .htaccess redirect not working?
Most often one of four things: AllowOverride is not enabled so the file is ignored entirely; the pattern starts with a slash (inside .htaccess the leading slash is stripped); an earlier rule with [L] matched first; or your browser cached a previous 301. Test in a private window with curl -I.
What is the difference between Redirect and RewriteRule?
Redirect comes from mod_alias — simple prefix matching, no conditions. RewriteRule comes from mod_rewrite — full regex, conditions and flags. Anything involving HTTPS, the hostname or the query string needs mod_rewrite. Never use both for the same path, because mod_alias wins whatever the order.
How do I force HTTPS in .htaccess?
RewriteCond %{HTTPS} off followed by RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]. Behind Cloudflare or a load balancer this loops forever, because the internal hop is plain HTTP — test %{HTTP:X-Forwarded-Proto} instead.
Does a redirect keep the query string?
With mod_rewrite, only if you add the QSA flag; without it the incoming query is dropped. With mod_alias, Redirect preserves the query automatically. Dropping it silently breaks UTM campaign attribution.
Should I use 301 or 302?
301 for permanent moves, 302 while you are still testing. Browsers cache 301s aggressively and often indefinitely, so a wrong 301 is very hard to undo — deploy with 302, confirm the destination, then promote it.

.htaccess redirects: rules, flags and the mistakes that break them

This .htaccess redirect generator writes Apache 301 and 302 rules for URL lists, HTTPS, www, domain moves and regex rewrites — with anchored patterns, loop detection and a tester that shows which rule wins. Below: how the two redirect modules differ, what each flag does, and why a rule that looks right does nothing.

What .htaccess actually is

.htaccess is a per-directory Apache configuration file. Apache reads it on every request, for every directory along the requested path, and applies whatever it finds — no restart needed.

That convenience is also its cost. Server-level config is parsed once at startup; .htaccess is parsed on every single hit. On a busy site the difference is measurable, which is why the standard advice is to develop rules in .htaccess and then move them into the vhost with AllowOverride None.

It only works if the server permits it. If AllowOverride is set to None for your directory, the file is ignored completely and silently — no error, no log entry, just a redirect that never happens.

mod_alias and mod_rewrite

Apache has two redirect systems. Knowing which you are using is most of the battle.

mod_aliasmod_rewrite
DirectivesRedirect, RedirectMatchRewriteRule, RewriteCond
MatchingPath prefix, or regex with RedirectMatchFull regex
ConditionsNoneRewriteCond on host, protocol, query, headers
Query stringPreserved automaticallyOnly with the QSA flag
Leading slashPresentStripped in .htaccess, present in vhost
SpeedSlightly fasterNegligibly slower
Use forSimple one-to-one movesHTTPS, www, domains, anything conditional
Never use both for the same URL. The modules run in different phases and mod_alias is applied first regardless of where the directives sit in the file. A RewriteRule above a Redirect for the same path will never fire, which reads as "Apache is ignoring my rule".

Redirect matches a prefix, not a page

This is the single most damaging misunderstanding in Apache redirects, because the broken behaviour looks correct in testing.

Redirect 301 /about /new-about does not redirect the page /about. It redirects everything beginning with /about:

  • /about → /new-about — as intended.
  • /about-us → /new-about-us — not intended.
  • /about/team → /new-about/team — not intended.
  • /about.html → /new-about.html — usually a 404.

You test /about, it works, you ship it, and three unrelated pages break. The fix is an anchored RedirectMatch: RedirectMatch 301 ^/about$ /new-about. The ^ and $ make the match exact, and this generator always emits them.

The flags that matter

FlagEffectWhen you need it
R=301Send an external redirect with this status.Always, for a redirect. Without R the rewrite is internal and the URL bar never changes.
LStop processing further rules.Almost always. Omitting it lets later rules rewrite your result again.
QSAAppend the incoming query string.Whenever campaign or tracking parameters must survive.
QSDDiscard the incoming query string.When a legacy parameter must not reach the new URL.
NCCase-insensitive matching.After migrating from Windows or IIS hosting.
NEDo not escape special characters in the target.When the destination contains # or a literal ?.
GReturn 410 Gone.Removing a page permanently, faster than waiting on 404s.
$N and %N are not the same. $1 is a capture from the RewriteRule pattern; %1 is a capture from the preceding RewriteCond. Host-based rules need %1, and using $1 there is why so many copied www rules redirect to the wrong place.

Forcing HTTPS behind a proxy

The textbook rule is RewriteCond %{HTTPS} off then RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]. On a plain server it is correct.

Behind Cloudflare, a load balancer, or most managed and cloud hosting, it produces an infinite loop. TLS terminates at the proxy, so Apache sees plain HTTP on the internal hop, redirects to HTTPS, the proxy forwards HTTP again, and the browser gives up with ERR_TOO_MANY_REDIRECTS.

The fix is to test the header the proxy sets instead:

  • RewriteCond %{HTTP:X-Forwarded-Proto} !https — the common convention.
  • On some hosts, %{HTTP:CF-Visitor} or a provider-specific variable.
  • Best of all, terminate the redirect at the proxy or CDN so the request never reaches Apache.

Tick “Behind a proxy or load balancer” and the generator emits the header form.

Why a rule silently does nothing

In rough order of how often each is the culprit:

  1. AllowOverride is None. The whole file is ignored. Nothing is logged. Check the vhost, not the file.
  2. A leading slash in the pattern. In .htaccess the path is matched without it, so ^/blog/ can never match. Examples copied from vhost config always have this.
  3. An earlier rule matched with [L]. Processing stopped before reaching yours. Order matters absolutely.
  4. The browser cached an old 301. Your rule is fine; you are not reaching the server. Test in a private window or with curl -I.
  5. mod_alias is shadowing it. A Redirect anywhere in the file beats every RewriteRule for the same path.
  6. An unescaped dot. . matches any character, so ^page.html$ also matches pageXhtml — and more importantly your intended literal may be matched by an earlier, broader rule.
  7. The file has Windows line endings or a BOM. Apache can reject the first directive outright, sometimes with a 500.
A syntax error in .htaccess takes down the entire directory with a 500 — every page, immediately. Always keep a known-good copy, and wrap rules in <IfModule> so a missing module degrades to “no redirect” rather than “site offline”.

Choosing the status code

301 Moved Permanently

The default for a real move. Cached hard by browsers, sometimes forever — which is why you deploy with 302 first and promote it once confirmed.

302 Found

Temporary. Search engines keep the original indexed. Correct for maintenance pages, tests and geolocation.

308 / 307

Permanent and temporary equivalents that preserve the request method and body. Use these for API endpoints and anything receiving POST.

410 Gone

No destination — the resource is deliberately removed. Search engines drop it faster than a 404.

Related searches

htaccess redirect generatorapache 301 redirecthtaccess 301 redirectrewriterule generatorforce https htaccesshtaccess www redirectredirectmatch vs redirecthtaccess redirect not workingmod_rewrite flagshtaccess trailing slashapache redirect query stringhtaccess domain migration