An htaccess redirect generator writes the exact Apache syntax for you, so a single misplaced flag or missing slash doesn't take your site offline. This free tool builds copy-ready rules for the redirect scenarios that come up constantly in real SEO work — permanent 301s, temporary 302s, forcing HTTPS, forcing or removing www, redirecting an entire domain, wildcard directory moves, and bulk 301 lists for migrations.
Redirects look simple until they go wrong, and when they go wrong they tend to go wrong expensively: lost rankings, lost backlinks, or a site that returns a 500 error to every visitor. This generator writes standard Apache syntax, and the notes below explain where each form can bite so you can check the output before it goes live.
What This Htaccess Redirect Generator Does
Pick the redirect scenario that matches what you're actually trying to do, enter the old and new paths, and the tool writes valid .htaccess syntax using Apache's mod_rewrite module (RewriteEngine/RewriteCond/RewriteRule) or the simpler Redirect directive from mod_alias, depending on which is the right tool for that job. The bulk mode accepts a full list of old-URL-to-new-URL pairs and generates one clean 301 rule per line — ideal for site migrations where dozens or hundreds of URLs changed at once.
Which module each type uses matters. The single 301, single 302 and bulk modes write Redirect lines (mod_alias), which match by URL-path prefix: Redirect 301 /old-page/ /new-page/ also sends /old-page/anything to /new-page/anything. HTTPS, www, remove-www, domain and wildcard write mod_rewrite rules. The www and remove-www rules also send visitors to https in the same step, and the domain rule sends to an https destination. The tool does not check that your paths are sensible, so read the output before you copy it.
Two things to know. Redirect whole domain has its own Old domain and New domain fields (a pasted https:// prefix, path or leading www. is stripped from the old domain). In single mode the old value must be a path starting with /, because Redirect does not accept a full URL as its source; a full URL produces an error comment instead of a rule. In bulk mode each line is split at the first comma, so the old URL cannot contain a comma, and lines without a comma are skipped silently.
How to Use It
- Choose your redirect type from the dropdown — this determines which fields you need to fill in.
- Enter your old and new values. For single and wildcard redirects, the old value is a path such as
/old-page/and the new value is a path or a full URL. For a whole-domain move, enter the two domains instead. - For bulk moves, choose "Bulk 301s" as the type and paste one "old,new" pair per line.
- Generate and review the output carefully — check that every old path and new path is correct before copying.
- Back up your current .htaccess file, then paste the new rules near the top of the file, above any existing
RewriteEngineblock if one already exists (see the note on multiple rule blocks below). - Test immediately after uploading — visit a redirected URL directly and confirm it lands on the right page with the correct status code.
301 vs. 302 — The Mistake That Costs Rankings
This is the most consequential decision in this whole tool. A 301 redirect tells browsers and search engines "this page has moved permanently". According to Google, a permanent redirect is a signal that the redirect target should be the canonical URL, and the target is what Google shows in search results. A 302 redirect says "this is temporary": Google's documentation says temporary redirects keep the source page in search results and are a weaker signal that the target is canonical. Google does not publish how much ranking value moves with either type, so treat a 301 as the correct way to ask for the move, not as a guarantee.
Using a 302 for a permanent page move is a common mistake. It happens by accident, because a developer's default redirect snippet or a CMS plugin may use 302 (note that Apache's RewriteRule with a bare [R] flag is a 302 by default), and the result is that the old URL can keep showing in search while the new one is slow to take its place. According to Google's documentation on redirects, use a permanent server-side redirect when a page has moved for good, and a temporary one only when you want the original URL to stay in results, such as a page that is briefly unavailable, an A/B test or a seasonal redirect you intend to reverse.
Never Redirect Everything to the Homepage
When a site migration goes wrong, the fallback instinct is often "just redirect anything broken to the homepage." Don't. Visitors who clicked a link to a specific page land somewhere they did not ask for, and Google may treat such redirects as soft 404s: Google describes a soft 404 as a URL that returns a normal response while the content looks like an error or a page that does not answer the request. Whether a given redirect is flagged is Google's call, but a redirect to an unrelated page is never a legitimate substitute for the missing content.
The correct approach is always to redirect each old URL to its closest genuine equivalent — the same product under a new URL, the merged article that now covers that topic, the new category page that replaced the old one. If no reasonable equivalent exists anywhere on the site, it is more honest, and often better for SEO, to let that URL return a real 404 (or a 410 Gone if it's permanently retired) than to fake a redirect to an unrelated page.
Avoid Redirect Chains
A redirect chain happens when URL A redirects to URL B, which itself redirects to URL C. Each additional hop adds latency for the visitor and adds one more point where something can break. Over years of site changes, chains build up invisibly — a page redirected during one migration gets redirected again during the next, and nobody goes back to update the original rule to point straight at the final destination. Periodically audit your redirect rules and update any old rule that now points to another redirect, so it points directly at the final live URL instead.
Forcing HTTPS and WWW Consistency
Every site should serve exactly one canonical version of every URL — not four (http/https × www/non-www). Mixed signals across those four variants can split link signals and leave search engines unsure which version is canonical. The "Force HTTPS" and "Force www" (or "Remove www") options in this generator write the RewriteCond/RewriteRule pairs that collapse all variants into one, using a 301 so the consolidation is treated as permanent. Both www options also force https in the same step, so you do not need to run the HTTPS rule separately when you use either of them. Apache's own mod_rewrite documentation is the authoritative reference for the syntax these rules are built on.
Backing Up Before You Touch .htaccess
A single typo in .htaccess — a missing closing bracket, an unescaped special character in a regex, a rule referencing a module that isn't enabled — can cause an Internal Server Error (500) across your entire site, not just the page you were trying to redirect. Before pasting any generated rules, download a copy of your current .htaccess file so you can instantly restore it if something breaks. After uploading new rules, load a few pages of your site immediately, including the homepage, to confirm the site is still up before moving on to anything else.
Where Redirect Rules Belong in the File
Order matters in .htaccess. Apache reads rules from top to bottom and, for mod_rewrite rules with the [L] flag, stops processing further rewrite rules once a match is found and applied. If you're adding redirects to a file that already has an existing RewriteEngine On block — common on WordPress sites, which insert their own permalink rewrite rules — paste the new RewriteCond/RewriteRule lines above the rules the CMS manages, so your redirects are evaluated first. A repeated RewriteEngine On line is harmless; what matters is the order of the rules. Simple Redirect 301 lines (mod_alias syntax, not mod_rewrite) are less order-sensitive and can typically go anywhere near the top of the file. mod_alias and mod_rewrite are separate modules, so if you mix them, test that the rule you expect is the one that fires.
Testing Redirects Properly
Don't rely on your browser alone to confirm a redirect works — browsers cache redirects aggressively, especially 301s, which can make a broken rule look like it's still working correctly for days after you've tried to fix it. Test in a private/incognito window, or better, use a command-line tool like curl -I https://example.com/old-page/ to see the raw HTTP response headers, including the status code (301 vs. 302 vs. 200 vs. 500) and the exact Location header the server is sending. This confirms precisely what search engines and other automated tools will see, independent of any caching in your own browser.
Redirects and Query Strings
Query strings need a decision. When a RewriteRule substitution contains its own ? query, the Apache documentation says the default is to discard the existing query string and use the new one, and the [QSA] flag combines the two. None of the rules this tool writes has a ? in its substitution, so you do not need [QSA] for them. The other limit is matching: Redirect works on the URL path, so it cannot redirect one specific query string, such as /page?id=12. Apache's mod_alias documentation points to mod_rewrite for anything that manipulates the query string, usually with a RewriteCond %{QUERY_STRING} line.
How to Read the Result
- The headline counts the redirect rules generated. A Force HTTPS rule counts as one rule even though it takes three lines, so use "Lines generated" to see the real size of the block.
- Type echoes your choice. RewriteEngine needed says No for the
Redirect-based modes (single and bulk), because those lines work without it, and Yes for the rewrite-based ones, where the output already starts withRewriteEngine On. - The output box is plain text. Nothing is tested against your server, so the tool cannot tell you whether your paths exist.
Here is what each type writes for typical inputs, taken from the tool itself:
| Setup | What it writes | Rules / type / lines / engine |
|---|---|---|
301, /old-page/ to /new-page/ (default) | Redirect 301 /old-page/ /new-page/ | 1 / 301 / 1 / No |
| 302, same paths | Redirect 302 /old-page/ /new-page/ | 1 / 302 / 1 / No |
| Force HTTPS | RewriteCond %{HTTPS} off, then RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | 1 / HTTPS / 3 / Yes |
| Force www | RewriteCond %{HTTP_HOST} !^www\. [NC], then a rule to https://www.%{HTTP_HOST}%{REQUEST_URI} | 1 / WWW / 3 / Yes |
| Remove www | RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC], then a rule to https://%1%{REQUEST_URI} | 1 / REMOVEWWW / 3 / Yes |
Whole domain, https://old-site.com to https://new-site.com | RewriteCond %{HTTP_HOST} ^(www\.)?old-site\.com$ [NC], then RewriteRule ^(.*)$ https://new-site.com/$1 [L,R=301] | 1 / DOMAIN / 3 / Yes |
| Whole domain with the default domain fields | ^(www\.)?olddomain\.com$ and https://newdomain.com/$1: replace both with your real domains | 1 / DOMAIN / 3 / Yes |
Wildcard, /blog to /articles | RewriteRule ^blog/(.*)$ /articles/$1 [L,R=301] | 1 / WILDCARD / 2 / Yes |
| Bulk, three "old,new" lines | three Redirect 301 old new lines | 3 / 301 (bulk) / 3 / No |
| Bulk, lines with no comma | a # comment saying no valid pairs were found | 0 / 301 (bulk) / 1 / No |
What to Do Next
- Back up the current
.htaccess, paste the rules, and load the homepage straight away to catch a 500 error. - Check each redirected URL with
curl -Iand confirm the status code and theLocationheader. - For a migration, list every old URL with its closest new equivalent first; the site migration risk calculator helps you size the job.
- Update internal links and your sitemap to point at the new URLs, so crawlers are not sent through redirects.
- Look up unfamiliar status codes in the HTTP status code lookup.
Redirect mapping is one of the highest-risk parts of any migration. Arb Digital plans and executes full redirect strategies as part of our SEO services, so nothing gets lost in the move.
See Our SEO Services All Free ToolsCommon Mistakes to Avoid
- Using 302 for a permanent move. It tells Google the move is temporary, so the old URL can stay in results.
- Mass-redirecting broken URLs to the homepage. Google may treat this as a soft 404, and visitors land somewhere they did not ask for.
- Not backing up .htaccess first. A syntax error can bring down the whole site with a 500 error.
- Building redirect chains. Always point a rule at the final live URL, not at another redirect.
- Forgetting trailing slashes.
/pageand/page/can behave differently depending on server config — be consistent. - Pasting a full URL as the old value in single mode.
Redirectonly matches paths, so the tool shows an error; use the path, or the whole-domain mode for a domain move. - Not testing after deployment. Visit the redirected URLs directly and confirm both the destination and the status code are correct.
Related Free Tools From Arb Digital
Once your redirects are live, make sure moved pages are properly discoverable with the XML sitemap generator and correctly referenced in your robots.txt generator. Confirm your new URLs are getting indexed with the Google cache checker, review on-page tags with the meta tag generator, add structured data with the schema markup generator, or browse our full free online tools hub.
Frequently Asked Questions
A 301 tells search engines a page moved permanently, and Google treats it as a signal that the new URL should be the one shown in results. A 302 signals a temporary move and Google keeps the original URL in results. Use 301 for permanent changes; reserve 302 for situations you intend to reverse.
No. Visitors land on a page they did not ask for, and Google may treat redirects to an unrelated page as soft 404s. Redirect each URL to its closest genuine equivalent, or let truly obsolete URLs return a real 404 or 410.
A redirect chain is when one redirect points to another redirect instead of the final live URL. Each extra hop adds load time and another point of failure. Periodically audit and flatten chains so every rule points directly at the final destination.
Without consolidation, your site can be reached at four different URL variants (http/https, www/non-www), which can split link signals and leave search engines unsure which is canonical. Forcing HTTPS and choosing one www version with 301 redirects collapses everything into a single URL.
Yes. A syntax error in .htaccess, like a malformed regex or missing bracket, can trigger a 500 Internal Server Error across the entire site, not just the redirected page. Always back up your current .htaccess file before adding new rules, and test the live site immediately after uploading.
Use single mode for a one-off page move or domain-level rule like forcing HTTPS. Use bulk mode when migrating a site or restructuring URLs at scale, where you need many old-URL-to-new-URL 301 pairs generated consistently and quickly.