About the Redirect Generator (.htaccess / Nginx)
This redirect generator turns a list of old and new URLs into ready-to-paste redirect rules for Apache .htaccess (mod_alias Redirect or mod_rewrite RewriteRule), Nginx and Netlify’s _redirects file. Paste one mapping per line — separated by a space, tab, comma or an arrow — and it normalises full URLs to paths, escapes regular-expression characters, handles query-string URLs, and skips duplicates, blank lines and self-redirects that would cause a loop.
It is built for site migrations, URL restructures, domain moves and cleaning up broken links found in Search Console. Permanent 301 redirects pass visitors and search engines to the new address and tell Google the move is permanent, which preserves rankings far better than letting old URLs return 404 errors.
Everything runs in your browser; nothing is uploaded. Always test new rules on a staging copy or with a few URLs first — a single wrong rule in .htaccess can break a whole site — and keep redirects in place for at least a year after a migration.
How to use the redirect generator (.htaccess / nginx)
- 1Paste your redirect map, one old and new URL per line.
- 2Choose your server: Apache .htaccess (Redirect or RewriteRule), Nginx or Netlify.
- 3Pick 301 for permanent moves or 302 for temporary ones.
- 4Copy the rules into your .htaccess, server block or _redirects file.
- 5Test a few old URLs in a browser or with curl -I before going live.
Formula and method
Each line is split into an old and a new URL. Full source URLs are reduced to their path (and query string), and relative targets get a leading slash; absolute targets such as a new domain are kept as written. Duplicate sources keep the first rule, and a source that points to itself is skipped to avoid an infinite loop.
For mod_alias the generator writes Redirect lines, which match by path prefix, ordered longest path first because the first matching Redirect wins; a homepage source is written as an exact RewriteRule so it does not catch every URL. For mod_rewrite it writes anchored RewriteRule patterns with regex characters escaped, so only the exact path matches; query-string sources get a RewriteCond on %{QUERY_STRING} and the QSD flag drops the old query. Nginx uses exact-match location blocks, or a $request_uri check for query-string URLs, and Netlify uses its space-separated _redirects syntax.
Worked examples
Mixed list for Apache .htaccess
Three plain paths become Redirect 301 lines, longest path first (the full example.com URL is reduced to /about-us.php). The /products?id=42 source cannot be matched by mod_alias, so it is written as a RewriteCond on the query string plus a RewriteRule with the QSD flag.
Exact-match rules for Nginx
/a gets an exact-match location block. Because Nginx locations ignore the query string, /c?x=1 is matched against $request_uri instead.
RewriteRule with escaping, a duplicate and a loop
The dot in old.php is escaped so it only matches a literal dot. The second /old.php line is a duplicate and /same → /same would loop forever, so both are skipped and reported.
Temporary redirects for Netlify
Netlify’s _redirects format is “from to status”. A 302 tells search engines the move is temporary, which suits a seasonal campaign URL.
Frequently asked questions
How do I add a 301 redirect in .htaccess?+
Add a line such as “Redirect 301 /old-page /new-page” to the .htaccess file in your site root (Apache with mod_alias). For exact matching or query strings use mod_rewrite: “RewriteEngine On” followed by “RewriteRule ^old-page$ /new-page [R=301,L]”.
What is the difference between a 301 and a 302 redirect?+
A 301 is permanent: browsers may cache it and search engines transfer the old URL’s signals to the new one. A 302 is temporary, telling search engines to keep the original URL indexed. Use 301 for migrations and 302 for short-term campaigns or maintenance.
Why does my Redirect rule also redirect other pages?+
Apache’s mod_alias Redirect matches by prefix, so “Redirect 301 /blog /news” also sends /blog/post to /news/post. Use a RewriteRule with ^ and $ anchors, or RedirectMatch, when you need an exact match.
How do I redirect a URL with a query string?+
Path-based rules ignore the query string. In Apache use RewriteCond %{QUERY_STRING} with a RewriteRule; in Nginx test $request_uri or $arg_name. The QSD flag (Apache 2.4+) stops the old query string being appended to the new URL.
Do redirects hurt SEO?+
Google says permanent server-side redirects are the best way to move a page and that they pass ranking signals. Problems come from redirect chains, loops and redirecting many pages to an irrelevant page such as the homepage, so map each old URL to its closest equivalent.