Htaccess Redirect Generator

Generate .htaccess redirect rules โ€” 301, 302, HTTPS, www, and canonical redirects

Redirect all other domains to this one

No redirect rules added. Click "Add Rule" to start.

RewriteEngine On

About This Tool

The .htaccess file is a powerful configuration file used by Apache web servers to control URL redirections, access rules, and more. Writing redirect rules by hand can be error-prone โ€” a single syntax mistake can break your entire site. This tool generates correct, production-ready .htaccess redirect rules for the most common use cases: permanent (301) and temporary (302) redirects, forcing HTTPS, www canonicalization, and domain-level redirects. Just configure what you need and copy the generated code. All redirects use Apache's mod_rewrite module, which is supported by virtually every shared hosting provider and dedicated server running Apache.

How to Use

1. Toggle "Force HTTPS" if you want all HTTP traffic redirected to HTTPS 2. Choose a WWW preference โ€” redirect www to non-www, or non-www to www 3. Optionally set a canonical domain if you have multiple domains pointing to one site 4. Add individual redirect rules (301 for permanent, 302 for temporary) 5. Click "Copy to clipboard" and paste the code into your .htaccess file 6. Upload the .htaccess file to your web server's root directory

Frequently Asked Questions

What is the difference between a 301 and 302 redirect?
A 301 redirect is permanent โ€” it tells search engines to transfer all SEO value (link equity) to the new URL. A 302 redirect is temporary โ€” search engines keep the original URL indexed. Use 301 for permanent URL changes and 302 for temporary ones (maintenance, A/B testing).
Where do I put the .htaccess file?
Place the .htaccess file in the root directory of your website (the same folder as your index.html or index.php). If the file already exists, add the generated rules at the top, after any existing RewriteEngine On directive.
Will this work on Nginx servers?
No, .htaccess files are specific to Apache web servers. Nginx uses a different configuration syntax. If you're using Nginx, you'll need to add redirect rules to your nginx.conf or site configuration file.
Should I redirect www to non-www or non-www to www?
Either works fine for SEO โ€” the important thing is to pick one and be consistent. Non-www (example.com) is more common for modern sites. Choose whichever version you've already set as your canonical URL in Google Search Console.
Can I use this for WordPress sites?
Yes. WordPress runs on Apache and uses .htaccess by default. Add the generated rules at the top of your existing .htaccess file, before the WordPress rewrite rules (the block starting with # BEGIN WordPress).