Redirect Non www. Pages to www.

/Redirect Non www. Pages to www.

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.

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 row_column_index="0_1" 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.

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]

2018-02-02T03:09:31+00:00December 30th, 2014|Programming Tips, Web Programming|0 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.