4

Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas

Zabs
  • 13,852
  • 45
  • 173
  • 297
  • possible duplicate of [non-www to www htaccess redirect](http://stackoverflow.com/questions/3707319/non-www-to-www-htaccess-redirect) – Quentin Feb 16 '12 at 16:03

1 Answers1

9

Relatively easily.

Match anything that does not begin with 'www.' and then redirect to the 'www.' version:

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