Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess - get all non-www traffic redirected to the www

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

like image 607
Zabs Avatar asked Jan 18 '23 11:01

Zabs


1 Answers

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]
like image 67
zaf Avatar answered Jan 30 '23 00:01

zaf