.htaccess Redirect Rule Generator
Generate correct .htaccess redirect rules without memorizing Apache rewrite syntax.
Redirects any HTTP request to the same URL on HTTPS. No fields needed, applies site-wide.
.htaccess output
—
Everything runs in your browser. Nothing you configure here is uploaded or stored.
How it works
- 1
Choose a redirect type
Single URL, wildcard folder, force HTTPS, www/non-www, or full domain migration.
- 2
Fill in the relevant fields
Each type shows only the fields it actually needs.
- 3
Choose 301 or 302
301 for a permanent move, 302 for a temporary one.
- 4
Click Add Rule
The rule is added to a running list, combine as many rules as your .htaccess file needs.
- 5
Copy the combined output
A single RewriteEngine On declaration is added automatically if any rule needs it, followed by every rule in order.
- 6
Test before deploying to production
Always verify a new .htaccess file on staging, or keep a backup, before deploying rule changes to a live site.
About the .htaccess Redirect Rule Generator
Apache's redirect and rewrite syntax in .htaccess is genuinely powerful, capable of everything from a single simple redirect to complex pattern-based rewriting, but that power comes with unforgiving syntax where a single misplaced character or missing flag can break an entire site's routing. This tool generates correct .htaccess redirect rules for the situations that come up most often, a single URL, an entire folder, forcing HTTPS, switching between www and non-www, or migrating to a new domain entirely, and lets you stack several rules together into one combined file.
Redirect versus RewriteRule, two different tools for two jobs
Apache offers two genuinely different mechanisms for redirecting a request. The simple Redirect directive, from mod_alias, handles a single, exact URL mapped to a single destination, straightforward and readable, but unable to handle patterns or conditions. RewriteRule, from the more powerful mod_rewrite module, supports regular expression pattern matching, capturing part of a URL and reusing it in the destination, and conditional logic based on the requesting domain, protocol, or other request details. This tool uses the simpler Redirect directive for single URL redirects, where it's genuinely sufficient, and switches to RewriteRule for anything involving a pattern or a condition, matching the right tool to each job rather than reaching for the more complex syntax everywhere by default.
Why a wildcard folder redirect needs a capture group
Redirecting an entire folder of pages, moving every URL under /old-blog to the equivalent path under /blog, needs the destination to preserve whatever came after the folder name, /old-blog/my-post should become /blog/my-post, not just /blog for every single page. This is done with a capture group, the (.*) portion of the pattern, which captures everything after the folder name and makes it available as $1 in the destination. Getting this capture group and its placement exactly right is one of the most common places a hand-written wildcard rule goes wrong, generating a broken destination URL for every page in the folder at once rather than just the one rule.
Site-wide redirects: HTTPS, www, and domain migration
Force HTTPS, www to non-www or the reverse, and full domain migration are all variations on the same underlying pattern, a RewriteCond checking something about the incoming request, the protocol or the hostname, followed by a RewriteRule that redirects to the corrected version while preserving the original request path. These are some of the most consequential .htaccess rules a site can have, since they apply to every single page rather than one specific URL, which also means a mistake in one of these rules affects the entire site at once, making it especially worth generating correctly rather than adapting a rule copied from somewhere else that may not exactly match your domain or situation.
Stacking multiple rules into one file, in the right order
A real .htaccess file usually needs several rules together, forcing HTTPS, redirecting www to non-www, and a handful of specific page redirects, all combined into a single file. Add Rule appends each generated rule to a running list, and the combined output includes a single RewriteEngine On declaration at the top only if at least one rule actually needs it, avoiding a redundant or missing declaration. Rules apply in the order they appear in the file, so site-wide rules like forcing HTTPS are generally worth adding before more specific page-level redirects, matching how Apache actually processes the file top to bottom.
Runs entirely in your browser, and one honest caution
Every rule is generated directly in your browser, nothing you configure is sent to a server. One genuine caution worth stating plainly, since a mistake in a site-wide .htaccess rule can take an entire site offline or create a redirect loop: always test a new .htaccess file on a staging environment or keep a backup of the working version before deploying rule changes to a live production site. Once your redirects are live, our Redirect Chain Checker confirms they resolve correctly with no unexpected extra hops, part of the same Technical SEO Tools collection this tool belongs to.
Frequently asked questions
Does this generate 301 or 302 redirects?
Both are supported. 301 is used for permanent redirects, which pass SEO value to the destination, while 302 is used for temporary redirects.
Can I generate a wildcard redirect for an entire folder?
Yes, wildcard and pattern-based redirect rules are supported alongside single URL redirects, using a capture group to preserve the path after the folder name.
What's the difference between Redirect and RewriteRule?
Redirect handles a single exact URL simply and directly. RewriteRule, from mod_rewrite, supports pattern matching and conditional logic, needed for wildcards, HTTPS forcing, and domain-level redirects.
Can I combine multiple redirect types into one file?
Yes, Add Rule appends each generated rule to a running list, and the final output combines them all with a single RewriteEngine On declaration if needed.
Does rule order in the file matter?
Yes, Apache processes rules top to bottom. Site-wide rules like forcing HTTPS are generally worth placing before more specific page-level redirects.
Is it safe to deploy a new .htaccess file directly to production?
Test it on a staging environment or keep a backup of the working version first. A mistake in a site-wide rule can take an entire site offline or create a redirect loop.
Does mod_rewrite need to be enabled on my server?
Yes, RewriteRule-based rules require Apache's mod_rewrite module to be enabled, standard on most shared hosting but worth confirming with your host if a rule doesn't seem to take effect.
Is my configuration uploaded anywhere?
No, all rules are generated entirely in your browser. Nothing you configure is sent to a server.