Htaccess Redirect Generator


1. Select redirect type





2. Enter your domain name


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

3. Get your code


4. Copy the code to your .htaccess file



About Htaccess Redirect Generator

The .htaccess file provides a way to make configuration changes to your website on a per-directory basis. The file is created in a specific directory that contains one or more configuration directives that are applied to that directory and its subdirectories. So if for any reason you want to create Redirections for certain URLs, Load custom error pages, Force your website to HTTPS instead of HTTP or www to non www, Allow or deny specific IP addresses access to your website or Password-protect certain directories on your server, the .htaccess file is the file to make changes to.

For SEO purposes, Google and the search engines would penalize you for duplicate content if you have a www and a non www versions of your website. For this reason, you should restrict access to either www.website.com or website.com. Some links may be outside of your website scope, and/or the search engines may have already indexed your website under both addresses if you have had your website for a while.

Your primary .htaccess file is located in your public_html folder. Inside we can add some code to redirect a www to non www or a non www to www permanently.

 

How to Make Redirection From Non-WWW to WWW or WWW to Non WWW Domain

You need to use the RewriteEngine module in the .htaccess file. First of all, you need to turn on the RewriteEngine module in the .htaccess file and then specify the conditions you want to check. If those conditions are satisfied, then you apply rules to those conditions.

To make the 301 redirect from www to non-www, this is the right code to be added to the htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} www.yourwebsitehere.com
RewriteRule (.*) http://yourwebsitehere.com/$1 [R=301,L]

Or if you want to make 301 redirect from non-www to www domain, this is the right code to be added to the htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

If you want to force your website to use WWW or force a WWW to use Non WWW, you need to use the RewriteEngine module in the .htaccess file. First of all, you need to turn on the RewriteEngine module in the .htaccess file and then specify the conditions you want to check. If those conditions are satisfied, then you apply rules to those conditions.

Let's go through each line.

The first line tells apache to start the rewrite module. RewriteEngine on turns on the RewriteEngine module. This is required; otherwise, conditions and rules won't work.

The second line checks if there is a www or a non www entered into the browser.

The ^(.*)$ means that you can have a lot of characters, not only one. This is what we need because ^(.*)$ contains the requested URL without the domain.

The next part http://www.example.com/$1, describes the target of the rewrite rule. This is our "final" used domain name, where $1 contains the content of the (.*).

The next part is what does the 301 redirects for us automatically: [L, R=301]. L means this is the last rule in this run. After this rewrite, the webserver will return a result. The R=301 means that the web server returns a 301 moved permanently to the requesting browser or search engine.


How to Generate Redirect Code with Htaccess Code Generator

Sometimes its hard to remember this code, so its best to use an htaccess code generator every time you need to redirect your URL. The best Htacess redirect code generator is the SEOCentralTools htaccess code generator. SEOCentralTool' Htaccess Redirect Code Generator is a free SEO tool that creates 301 permanent redirection codes for www or non-www version of your website for SEO. The Htaccess Redirect Generator is part of our robust 100% free online SEO tools.

Using this tool is easy and all you have to do is:

1. Choose www to non www or www to non www.

2. Enter your domain name with the www

3. Click on Get access code.

 

 

4. The tool will generate the code based on which redirect type you want. All you need to do is copy the code and paste that in your existing .htaccess access file and save.

 

We do recommend a free online website analysis tool that offers complete access to the best-in-class proprietary metrics including PageSpeed Insights, Traffic rank, Keyword consistency, Text/HTML Ratio, Keyword Difficulty, Link analysis and more. Uncover technical SEO issues on your website wth this tool and get a get a fully custom, beautiful PDF reports with recommended improvements and fixes.