Htaccess Redirect Generator

Generate 301 redirect code for .htaccess files. Redirect from www to non-www or non-www to www versions of your domain instantly.

i

Create www to non-www or non-www to www 301 Redirect code for Htaccess using Turbo htaccess rewrite generator tool. Just follow below 3 steps and click on "Get .htaccess Code" button.

1. Select redirect type

2. Enter your domain name

Do not include www. Domain name only - e.g. yourdomain.com

3. Get your code

Your SEO Tip of the Day

Relevant Tools

What is .htaccess Redirect?

An .htaccess redirect is a server configuration directive that automatically sends visitors from one URL to another. The .htaccess file is a powerful configuration file used on Apache web servers to control various aspects of how your website functions, including URL redirects, security settings, and URL rewriting.

A 301 redirect is a permanent redirect that tells search engines the page has permanently moved to a new location. This is the most SEO-friendly type of redirect because it passes approximately 90-99% of link equity (ranking power) to the redirected page. It's essential for maintaining SEO value when changing URLs or consolidating duplicate content.

The www to non-www (or vice versa) redirect is particularly important for SEO because search engines treat www.example.com and example.com as two different websites. Without proper redirection, your link equity gets split between both versions, potentially harming your search rankings. By implementing a 301 redirect, you consolidate all traffic and SEO value to your preferred domain version.

Why Use .htaccess Redirects?

Implementing proper .htaccess redirects offers numerous benefits for your website:

  • Consolidate SEO Value – Combine the ranking power of www and non-www versions into one preferred domain.
  • Avoid Duplicate Content – Prevent search engines from seeing your site as duplicate content across different URL versions.
  • Better Analytics – Track all traffic in one place rather than split between multiple domain versions.
  • Professional Appearance – Maintain consistency in your branding by using one canonical URL format.
  • Improved User Experience – Visitors always see the same URL format regardless of how they access your site.
  • Link Equity Preservation – Maintain backlink value when you have links pointing to different versions of your domain.
  • Search Engine Preference – Tell search engines which version of your domain you prefer to have indexed.

How to Use the Generated Code

  • 1.Locate Your .htaccess File – Connect to your server via FTP or use your hosting control panel's file manager. The .htaccess file is typically located in your website's root directory (public_html or www folder).
  • 2.Backup First – Before making any changes, download a copy of your existing .htaccess file as a backup in case something goes wrong.
  • 3.Edit the File – Open the .htaccess file in a text editor. If the file doesn't exist, create a new one named ".htaccess" (including the dot at the beginning).
  • 4.Add the Code – Copy the generated code and paste it at the top of your .htaccess file, above any existing rules.
  • 5.Save and Upload – Save the file and upload it back to your server if you edited it locally.
  • 6.Test the Redirect – Visit both versions of your domain (www and non-www) to ensure the redirect is working properly.
  • 7.Check for Errors – If your site becomes inaccessible, restore your backup .htaccess file and double-check the code for typos.

Understanding the Code

  • RewriteEngine On – Activates the rewrite engine, which is necessary for URL redirects to work.
  • RewriteCond – Sets a condition that must be met for the redirect to execute. In this case, it checks if the domain starts with www (or doesn't, depending on your choice).
  • %{HTTP_HOST} – Refers to the domain name in the URL.
  • [NC] – Stands for "No Case," meaning the rule is case-insensitive (matches WWW, www, Www, etc.).
  • RewriteRule – Defines the actual redirect rule, specifying what to redirect and where.
  • [L,R=301] – L means "Last" (stop processing further rules), and R=301 specifies this is a permanent redirect.

Best Practices

  • Choose One Version – Decide whether you prefer www or non-www and stick with it consistently across all your marketing materials.
  • Update Google Search Console – Set your preferred domain version in Google Search Console after implementing the redirect.
  • Use HTTPS – If you have an SSL certificate, update the code to use https:// instead of http:// in the redirect URLs.
  • Test Thoroughly – Check various pages on your site, not just the homepage, to ensure redirects work correctly.
  • Monitor Traffic – After implementing redirects, monitor your analytics to ensure traffic is being properly consolidated.
  • Keep Backups – Always maintain backups of your .htaccess file before making changes.
👋 Need help?