Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How To 301 Redirect www to non www URLs Using HTACCESS

The internet is full of information and all of them are properly categorized or distinguished by Urls (Uniform Resource Locators). If you purchase a domain, you will naturally get two URLs for it i.e., www.example.com and example.com. Most of the browsers consider www and non-www URLs as one and the same. But in cases of search engines, it is a different story.

Almost all search engines consider www and non-www URLs as different pages of a website. So, if your website is not redirected from www to non-www or non-www to www version, search engines will consider that you have two pages of same content. This will result in duplicate content issue and because of this your website rankings will get affected.

So, to resolve this issue you will need to 301 redirect (permanent redirection) www addresses to non-www or non-www addresses of your website to www. Although there are different ways to do this task, the simple way is by using the .Htaccess file located in your server (Linux servers). Let’s find out the tutorial for redirecting www to non-www URLs and non-www to www URLs using .htaccess.

Tutorial To 301 Redirect www to non www URLs Using .htaccess:

1) To get started, log into the cPanel of your website and open the File manager (make sure that you have enabled “Show Hidden Files” option or else the .Htaccess File won’t show up under “File Manager”).

2) Next, add the following code in the .htaccess file:

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

Once done, save the file.

That’s it. Now, you have successfully redirected www addresses of your website to non-www.

Tutorial To 301 Redirect non www to www URLs Using .htaccess:

To 301 redirect non-www URLs of your website to www addresses, enter the following code in the .htaccess file in your server:

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

(Note: Replace example.com with your domain name).

Tutorial To Redirect example.com/index.php to example.com using .htaccess:

Since search engines consider all URLs as separate pages, you will need to redirect your index.php page (if you have created your website using .php then this will be your homepage) to the primary domain. To do so, enter the following code in .htaccess:

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]

(Note: Replace example.com with your domain name).

Make sure that you copy and paste the codes given here properly in your .htaccess file or else, your website will not work properly. Also, if you have any queries regarding 301 redirection of your website using .htaccess, drop a comment below.

The post How To 301 Redirect www to non www URLs Using HTACCESS appeared first on Crack Aloud.



This post first appeared on Crack Aloud - Useful Tips, Tricks And Tutorials, please read the originial post: here

Share the post

How To 301 Redirect www to non www URLs Using HTACCESS

×

Subscribe to Crack Aloud - Useful Tips, Tricks And Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×