webnat0
webnat0

Reputation: 2716

redirecting domain.com to www.domain.com in Apache 2

I heard search engines recognize domain.com and www.domain.com as different addresses. So redirecting domain.com to www.domain.com would be better for SEO.

How would you do it? I have access to apache.conf

Upvotes: 0

Views: 1832

Answers (2)

Sam Stainsby
Sam Stainsby

Reputation: 1608

<VirtualHost *:80>
    ServerName domain.com
    Redirect permanent / http://www.domain.com/
</VirtualHost>

Upvotes: 4

Zimbabao
Zimbabao

Reputation: 8240

You can put following lines in you .htaccess

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

If you want this only for SEO purpose then you can also make www.domain.com your prefererred domain in Webmasters Tools.

In Google webmaster you can do
1.Goto https://www.google.com/webmasters/tools/settings?
2. Under "site configurations > settings" you can set your preferred domain.

Upvotes: 2

Related Questions