When building a website, from time to time it’s necessary to redirect the non www. version of the website to the www. version, especially since you’re then less likely to have two versions of your website in the Google SERPS.

And since a web client of mine is asking how this is done, I’ll share the most common method, a few simple lines in your .htaccess file in the website’s root folder.

#REDIRECT TO WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"][R=301,L]

Pretty simple, huh? And for completion, here’s the redirect from www. to the non www. version.

#REDIRECT TO NON WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} !^web-programmer\.com$ [NC]
RewriteRule ^(.*)$ http://web-programmer/$1 [R=301,L]

That’s really all there is to it. Tidy, useful and consistent. Everything a web development project should be.[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]