Apache Server How To Redirect To WWW instaed of getting default http://mysite.com

maxlinks

Regular Member
Jr. VIP
Joined
Jul 4, 2011
Messages
469
Reaction score
60
I have an appache server with 20 web sites,
I want them all to be www.mysite.com instead of http://mysite.com

it seems google picks them up as http://mysite.com and picks up the default web site first, is there a way to tell apache not to go to default website,

all parameters in sites-enabled are ok (I hope), all pointing to www.

is there something in the httpd file I should change ?
 
Forgot someone once told me to ad

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]


to each web site directory, however , I think my server is bypassing that and going straight to default , only for a few sites, I assume if you dont tell google you want www.mysite.com then they pick out http://mysite.com and then that goes straight to my default site since I indicate www in the sites-enabled configuration.
 
that code is right , did you put it in a .htaccess file in each site directory?
 
I will double check, but I suspect that its not even looking in the individual directories and just going to default ?
 
use this code:
PHP:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Put the code on the .htaccess of the root directory of every site, eg: public_html
 
Back
Top