301 Redirect Code Generator
Generate 301 redirect code for Apache .htaccess, Nginx, IIS, PHP, JavaScript, HTML meta, Cloudflare, and WordPress. Bulk import and export.
About
A misconfigured redirect loses link equity and fractures crawl budgets. Search engines treat a 301 (Moved Permanently) differently from a 302 (Found / Temporary): only the former passes approximately 95% of accumulated PageRank to the destination URL. Getting the syntax wrong on Apache versus Nginx versus IIS means the directive is silently ignored and the old URL returns a 404, compounding organic traffic loss at a rate proportional to the page's backlink profile. This tool generates syntactically correct redirect directives for 8 server environments, validates source and target paths, and exports production-ready config files.
The generator supports HTTP status codes 301, 302, 307, and 308. It handles bulk imports so migrations involving hundreds of URLs can be processed in seconds rather than hand-typed. Note: regex-based redirects (RewriteRule patterns) are not generated here; this tool produces literal path-to-path mappings only. Always test generated config in a staging environment before deploying to production.
Formulas
A 301 redirect instructs HTTP clients via a response header:
Location: target_url
Apache .htaccess directive syntax:
Nginx location block syntax:
Where source_path = the old URL path (e.g., /old-page), and target_url = the full destination URL or path. The HTTP status code determines cache behavior: 301 is cached indefinitely by browsers, 302 is not cached by default, 307 preserves the request method (POST stays POST), and 308 is the permanent equivalent of 307.
PageRank transfer approximation:
Where PRoriginal is the PageRank of the source page before the redirect. This approximation is based on historical Google statements; the exact dampening factor is not publicly disclosed.
Reference Data
| Server / Method | Config File | Directive | Regex Support | Notes |
|---|---|---|---|---|
| Apache 2.4+ | .htaccess | Redirect / RewriteRule | Yes (mod_rewrite) | Requires mod_alias or mod_rewrite enabled |
| Nginx | nginx.conf | return 301 / rewrite | Yes (PCRE) | Requires nginx -s reload after edit |
| IIS 7+ | web.config | <httpRedirect> | Yes (URL Rewrite module) | XML-based; must be well-formed |
| PHP | Any .php file | header("Location: ...") | N/A (script logic) | Must be called before any output |
| JavaScript (client) | HTML <script> | window.location.replace() | N/A | Not crawlable by all bots; fallback only |
| HTML Meta | HTML <head> | <meta http-equiv="refresh"> | No | Delay in seconds; poor SEO signal |
| Cloudflare Pages | _redirects | /old /new 301 | Splats only (*) | Max 2000 rules; processed top-down |
| WordPress (PHP) | functions.php | wp_redirect() | N/A | Hook into template_redirect action |
| Vercel | vercel.json | redirects array | Yes (path patterns) | JSON config; max 1024 redirects |
| Netlify | _redirects / netlify.toml | /old /new 301! | Splats (:splat) | Force flag ! overrides existing file |
| Amazon S3 | Bucket policy (XML) | <RoutingRules> | Prefix only | Only prefix-based; no full regex |
| Firebase Hosting | firebase.json | redirects array | Glob patterns | Processed in order; first match wins |
| Caddy 2 | Caddyfile | redir | Yes (matcher) | Clean syntax; automatic HTTPS |
| Traefik | Labels / TOML | RedirectRegex | Yes | Middleware-based configuration |
| LiteSpeed | .htaccess | Same as Apache | Yes | Compatible with Apache directives |
Frequently Asked Questions
https://newdomain.com/page). For Nginx, the return 301 directive accepts absolute URLs natively. Cross-domain 301 redirects pass link equity the same way as same-domain redirects, though the receiving domain must be accessible and return a 200 status.Redirect directive automatically appends the query string from the original request to the target URL. To strip it, you need RewriteRule with a ? at the end of the target. Nginx's return 301 does not append query strings by default; use $is_args$args to preserve them. This generator produces literal path redirects; if your migration requires query string manipulation, you will need to manually adjust the output..htaccess has no hard limit but performance degrades linearly with rule count; beyond 1000 rules, consider using RewriteMap with a database or text file. Nginx handles large numbers efficiently since config is compiled at startup. Cloudflare Pages caps at 2000 rules. Vercel allows 1024. For very large migrations (10000+ URLs), server-side scripting (PHP/Node) with database lookups is more appropriate than static config files.