Htaccess Redirect Generator
301 redirects: www to non-www or vice versa. Enter domain, copy mod_rewrite rules for .htaccess.
What is Htaccess Redirect Generator?
Htaccess Redirect Generator is a free online tool that creates Apache .htaccess rules for 301 redirects between www and non-www versions of your domain. You enter your domain, choose redirect type (www to non-www or non-www to www), and the tool outputs ready-to-use RewriteRule code. Copy the code and paste it at the beginning of your .htaccess file. Webmasters and developers use it to canonicalize URLs, avoid duplicate content, and improve SEO. No account or signup is required.
The interface includes a domain input (with placeholder https://example.com) and two redirect type options: www to non-www (www.example.com to example.com) and non-www to www (example.com to www.example.com). The generated code appears in a textarea with copy functionality. An alert explains how to use the code: paste at the beginning of .htaccess. A collapsible About section describes the purpose of .htaccess redirects and SEO benefits.
Who Benefits from This Tool
Webmasters and site owners benefit when consolidating www and non-www. Search engines may treat them as duplicate content. A 301 redirect establishes a canonical URL and passes link equity. The tool makes it easy to generate correct rules.
Developers benefit when deploying or migrating sites. Ensure consistent URL structure. The generated code is standard Apache mod_rewrite; it works on most shared hosting.
SEO professionals benefit when auditing client sites. Canonicalization is a common recommendation. The tool provides the exact code to implement it.
Key Features
Domain Input
Enter your domain with or without protocol. The tool uses it to build the redirect rules.
Redirect Types
www to non-www: Redirects www.example.com to example.com. non-www to www: Redirects example.com to www.example.com.
Generated Code
Output is Apache RewriteCond and RewriteRule directives. 301 permanent redirect. Ready to paste into .htaccess.
Instructions
Alert explains placing the code at the beginning of .htaccess. Ensures it runs before other rules.
How to Use
- Enter your domain. Type the domain (e.g., https://example.com or example.com).
- Select redirect type. Choose www to non-www or non-www to www.
- Complete the captcha if required.
- Click Generate Code. The code appears in the output area.
- Copy the code. Paste it at the beginning of your .htaccess file. Upload or edit .htaccess in your site root.
Common Use Cases
- Canonicalizing www and non-www for SEO
- Avoiding duplicate content between URL variants
- Consolidating link equity to one URL
- Setting up new sites with correct redirects
- Fixing mixed www/non-www links from external sources
- Implementing SEO recommendations for URL consistency
Tips & Best Practices
Choose one canonical form (www or non-www) and stick to it. Use 301 (permanent) so search engines transfer link equity. Place the redirect rules at the top of .htaccess so they run first. Test after deployment: visit both www and non-www and confirm redirect. Update internal links and sitemaps to use the canonical URL.
Limitations & Notes
The tool generates Apache mod_rewrite rules. It requires Apache with mod_rewrite enabled. It does not work on Nginx or IIS; those servers need different configuration. Some shared hosts restrict .htaccess. Test in a staging environment if possible. The tool does not store your domain.