htaccess Redirect Generator
Build clean .htaccess redirect / rewrite rules from a visual editor. Simple path redirects, wildcard folder mappings, regex rewrites, force-HTTPS, add/remove www, force trailing slash. 301/302/307 status codes. 100% offline.
What is the htaccess Redirect Generator?
htaccess Redirect Generator is a visual builder for the most-used Apache `.htaccess` directives. Seven rule types: Simple redirect (`Redirect 301 /old /new` — single path to single path), Wildcard redirect (`RewriteRule ^/old/(.*)$ /new/$1` — folder-to-folder mapping that preserves the tail), Regex rewrite (`RewriteRule` with your own pattern), Force HTTPS (sends every HTTP request to the HTTPS equivalent), Add www (canonical `example.com` → `www.example.com`), Remove www (canonical `www.example.com` → `example.com`), and Force trailing slash (adds `/` to URLs that don't have one). Each rule has configurable HTTP status (301 permanent, 302 temporary, 307 preserve-method) and a toggle to preserve the query string (`[QSA]`). Output options include wrapping the entire block in `<IfModule mod_rewrite.c>` (safer when the module isn't loaded), an optional commented header, and a switch to use `RedirectMatch` (anchored regex) for the simple rule type if you need query-string regex matching. Pure string generation — no Apache validation, just well-formed directives.
How to use it
- Click 'Rule' to add a redirect; pick its type from the dropdown.
- Fill in the From / To paths (or hostname for www rules).
- Pick the HTTP status (301 / 302 / 307) and whether to preserve the query string.
- Reorder rules with the up/down arrows; copy or download the .htaccess.
Benefits
- 7 rule types covering the most-used Apache redirect patterns.
- Force HTTPS rule uses the canonical `HTTP_HOST` / `REQUEST_URI` pattern.
- Add/remove www rules use a `RewriteCond` with the precise host match (no false positives).
- Wildcard redirects preserve the URL tail with `$1` automatically.
- Configurable HTTP status (301 / 302 / 307) per rule.
- Query-string preservation via `[QSA]` flag.
- Optional `<IfModule mod_rewrite.c>` wrap for safe deployment.
- Reorder rules with up/down buttons — execution order matters in Apache.
- Persists your rules in localStorage for one-click resume.
- Runs 100% in your browser — Toollyz has no server.
Frequently asked questions
What's the difference between Redirect and RewriteRule?
`Redirect` is the simpler directive — single path to single path, status code in the directive itself. `RewriteRule` is the full mod_rewrite engine — pattern matching, conditions, multiple flags. Use Redirect for simple cases, RewriteRule when you need a pattern or query-string preservation.
What's 301 vs 302 vs 307?
301 = Permanent — search engines update their index. 302 = Temporary — search engines don't update. 307 = Temporary AND preserves the request method (POST stays POST), unlike 302 which most clients convert to GET.
Should I add www or remove it?
Pick one and stick with it (canonical hostname). Removing www is the modern convention for new sites; adding www is common for established sites with backlinks to `www.example.com`. Either way, redirect the non-canonical to the canonical with a 301.
What does `[QSA]` do?
Query String Append. When set, the original query string (`?foo=bar`) is preserved through the redirect. Without it, the destination URL drops the query string.
Why wrap in `<IfModule mod_rewrite.c>`?
Safer — if mod_rewrite isn't loaded, Apache silently skips the block instead of erroring out. Most production servers have it loaded but the wrap is cheap insurance.
Will my redirects work on Nginx?
No — .htaccess is Apache-specific. For Nginx use `try_files`, `return 301`, and `rewrite` directives in your server block. We don't currently emit Nginx config — that's a separate tool.
What's the difference between Redirect and RedirectMatch?
`Redirect` matches the path prefix; `RedirectMatch` matches an anchored regex (so `^/old$` only matches exactly `/old`, not `/oldarchive`). Toggle 'Use RedirectMatch' if you need the stricter anchored matching.
Why does the trailing-slash rule check `!-f` and `!-d`?
To skip files and directories — adding a trailing slash to `/index.html` would 404. The condition says 'only add a trailing slash if the path doesn't already point at a real file or directory'.
Do redirects affect SEO?
Yes. 301 redirects pass roughly 90-99% of the link equity from the old URL to the new one. Chains of multiple redirects (A → B → C) erode this further — keep redirect chains to one hop where possible.
Should I test before deploying?
Always. .htaccess errors can take a site down. Test with `curl -I` against staging before pushing to production.
Is anything uploaded?
No. Rule composition runs entirely in your browser.