Htaccess Redirect Generator

301 redirects: www to non-www or vice versa. Enter domain, copy mod_rewrite rules for .htaccess.

.htaccess Redirect Generator

About .htaccess Redirects

Generate 301 redirect rules for your .htaccess file to redirect www to non-www or vice versa. Helps avoid duplicate content issues and improves SEO.

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

  1. Enter your domain. Type the domain (e.g., https://example.com or example.com).
  2. Select redirect type. Choose www to non-www or non-www to www.
  3. Complete the captcha if required.
  4. Click Generate Code. The code appears in the output area.
  5. 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.

FAQs

Is the tool free?

Yes. No signup required. A captcha may appear.

Does it work on Nginx?

No. The output is Apache .htaccess. Nginx uses a different syntax. Use an Nginx redirect generator for that.

Where do I put the code?

Paste at the beginning of your .htaccess file in the site root. Ensure it appears before other RewriteRule blocks.

What if I use a subdomain?

The generated rules typically apply to the domain you enter. For subdomains, you may need separate config or adjust the rules.

Will it affect my existing .htaccess rules?

Placing at the beginning means it runs first. Other rules below may still apply. Review your full .htaccess for conflicts.

Do I need to include https?

The tool uses the domain you provide. For HTTPS, enter https://example.com. The redirect preserves the protocol in most cases.

What is a 301 redirect?

301 means permanent. Search engines transfer ranking signals to the new URL. Use 301 for permanent moves.

Can I redirect only the homepage?

The generated rules typically redirect all www to non-www (or vice versa) for the domain. For homepage-only redirects, you would need different rules.

Does it work on shared hosting?

Yes, if the host supports .htaccess and mod_rewrite. Most Apache-based shared hosting does.

Why is my redirect not working?

Check that mod_rewrite is enabled. Ensure .htaccess is in the root. Verify the domain and redirect type. Clear browser cache when testing.