Redirect www to non www with .htaccess RewriteRule

Google Analytics handles and as two different websites. So, you might get lower visitor statistics. To fix this, you can redirect all www to non www with .htaccess RewriteRule.

Let's get started. Open Notepad or any plain text editor.
Insert this code to your file and save it as .htaccess without any extension:

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

The final step is to upload this .htaccess file to your website root folder.


Related articles

Unordered List Style Image CSS

Unordered List Style Image CSS


Learn how to style UL with any image using CSS.

OL and UL List CSS Style

OL and UL List CSS Style


Styling ordered and unordered lists is easy. Just write a single line of CSS to change the list style type.

Email Validation

Email Validation


Learn how to validate email on client side with HTML5, Javascript and on server side with PHP.

Leave a comment

We welcome any comment from you! Please keep in mind that comments are moderated and rel='nofollow' is in use. So, please do not use a domain as your name or a spammy keyword, or your comment will be deleted.

Name: *

E-mail: *

Message: *

Click on the airplane *

Find us on Facebook



Back to Top