How to use htaccess Redirect Generator
- Choose a rule type and press Add rule, then fill in its fields: for a single page, the old path and the new URL.
- Pick the redirect type. Use 301 or 308 for permanent moves and 302 or 307 only for temporary ones.
- Read the warnings about loops, chains, rules that can never match and patterns that catch everything, and fix the rules they mention.
- Switch between the Apache and Nginx tabs, copy or download the result, back up your current file, paste it in and test with a tool like curl -I.
Features
- Single page redirects, exact or including sub-paths, with 301, 302, 307 or 308
- Pattern redirects with RedirectMatch or RewriteRule and captured parts such as $1
- Force HTTPS, with a variant for sites behind a proxy, and www to non-www or the reverse in one hop
- Add or remove the trailing slash, remove .html and redirect a whole domain to a new one
- Equivalent Nginx rules for every rule type
- Warnings for loops, chains, shadowed rules, catch-all patterns and mixed modules
- Rejects input with spaces, quotes or control characters, so it cannot inject extra directives
Examples
| Input | Result |
|---|---|
| Single page: /old-page to https://example.com/new-page, 301, exact path | RedirectMatch 301 "^/old-page/?$" "https://example.com/new-page" — The Nginx tab shows the matching location block. |
| Force HTTPS and www to non-www for example.com | One rule: RewriteCond %{HTTPS} off [OR], RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC], then RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301] — Both fixes happen in a single redirect. |
Limitations
- It writes rules, it does not test them. Always test on a copy of your site and check the result with curl -I or a redirect checker.
- The .htaccess rules need Apache with mod_alias or mod_rewrite and AllowOverride enabled. Nginx has no .htaccess, so its rules go in the server configuration.
- Nginx output uses return and rewrite in a typical layout. Certificates, upstreams and framework routing still need your own settings.
- Regex patterns are checked with JavaScript syntax. Apache and Nginx use PCRE, which is very similar but not identical.
- Redirects by query string and by host header beyond the domain move rule are not covered.
Learn more
A redirect sends visitors and crawlers from one URL to another. Redirects are how you keep links and search rankings working when you rename a page, restructure a site, switch to HTTPS, choose www or non-www, or move to a new domain. A permanent redirect, with status 301 or 308, tells search engines to treat the new URL as the replacement. A temporary one, 302 or 307, says the original will come back.
On Apache, rules live in a .htaccess file or the server configuration. The mod_alias module offers the simple Redirect and RedirectMatch directives, and mod_rewrite offers RewriteCond and RewriteRule for conditions and complex patterns. Nginx uses the rewrite and return directives inside server and location blocks. The behavior is similar, but the syntax and the order in which rules run are different, so this tool writes both.
Good redirects go straight to the final URL in one step, because chains waste time and crawl budget, and avoid loops, which break the page completely. Redirect to a page that really replaces the old one, since sending many unrelated URLs to the home page may be treated as a soft 404. Keep permanent redirects in place for at least a year after a move.
Frequently asked questions
What is a 301 redirect?
A 301 is a permanent redirect. It tells browsers and search engines that a page moved for good, so they can pass the old URL's signals to the new one.
When should I use 302 or 307?
Use them for temporary moves, such as a short maintenance page. Search engines may keep the old URL indexed, so use 301 or 308 when a move is permanent.
What is the difference between Redirect and RedirectMatch?
Redirect matches a path prefix, so it also redirects pages below that path. RedirectMatch uses a regular expression, so you can match exactly one URL or a whole pattern.
Why does the order of rules matter?
The first matching rule wins, so a broad pattern placed first can stop later, more specific rules from ever running. Put specific rules before general ones.
Is my configuration sent anywhere?
No. The rules are generated in your browser and nothing is uploaded.
Sources
- Google Search Central: redirects and Google Search
- Apache HTTP Server: mod_alias
- Apache HTTP Server: mod_rewrite
- Nginx: ngx_http_rewrite_module
Last reviewed: October 1, 2026