1

i have about 10 domains on my server

site1.com
site2.com
site3.com

i want redirect non-www to www

from site1.com to www.site1.com

from site2.com to www.site2.com

Should i add htaccess for each site?

can i short this job in apache config?

Alaa Gamal
  • 1,135
  • 7
  • 18
  • 28

1 Answers1

3

The following entry in your Apache configuration for each domain would do the trick. Note that you should be doing a 301 (permanent) redirect to make sure the search engines understand that your www address is the canonical one.

<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com

Redirect 301 / http://www.example.com
</VirtualHost>
DPlusV
  • 13,706
  • 1
  • 19
  • 18
  • i don't want to redirect all domains to an domain!! i want just replace non-www by www, but in all sites on the server, site1.com to www.site1.com and site2.com to www.site2.com – Alaa Gamal Jul 08 '12 at 01:34
  • Yes, you would copy the above entry to httpd.conf **for each** domain you want to redirect. Replace `example.com` with `site1.com`, for example. – DPlusV Jul 08 '12 at 01:35
  • that's mean i will repeat the code 10 times, but i am here to find something shorten – Alaa Gamal Jul 08 '12 at 01:36