简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM