问题
Ive just ran an seo audit on my site and received this message...
Be sure that www.mysite.co.uk and myside.co.uk are not running in parallel.
Redirecting requests from a non-preferred hostname is important because search engines consider URLs with and without "www" as two different websites.
Once your preferred domain is set, use a 301 redirect for all traffic to your non-preferred domain.
Now my website works with both www. and without the www. so does this mean my sites running in parallel?
If so how do i address this? and shall i point my non www to the www or the other way around?
Im using PHP on a linux/apache server.
回答1:
Now my website works with both www. and without the www. so does this mean my sites running in parallel?
Pretty much. Running in parallel means that a visitor (human or search engine robot) can access same content with www and non-www version of the URL.
The recommended practice is to have both hostnames active but redirect all traffic of the non-preferred hostname to the preferred one using 301 redirect.
If so how do i address this?
For Apache, place these rules in the .htaccess file located in the wwwroot directory:
#########################
# redirect no-www to www
#########################
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
-- or --
#########################
# redirect www to no-www
#########################
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
and shall i point my non www to the www or the other way around?
There is no definite answer; both have their pros and cons. See Yes WWW to understand why having a www URL is good, and its competitor No WWW which simply says "www. is deprecated." without an explanation.
回答2:
Indeed, keep available www and no-www versions for a web site can be hasardous because it generates duplicate content between two versions of your web site. And Google doesn't like duplicate content, that's why it's good seo pratice to redirect www to no-www or the opposite.
With Apache Server, you can create .htaccess file (in root of your domain) and insert these lines to redirect (301 redirect) www to no-www:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [QSA,R=301,L]
</IfModule>
You also can choose the opposite (redirect from no-www to www) if you prefer. No matter for seo if you choose one or other solution.
回答3:
I think you should redirect non-www to www using the .htaccess file:
Here is how to do it and some other useful tricks: http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
回答4:
www in www.domain.com is subdomain which can be anything. like ( m.domain.com , x.domain.com or anything.
But usually as per conventional approach www is default subdomain of any site.
Most of the sites refer www.sitename.com or sitename.com to same page.
So don't worry just go ahead..!!
来源:https://stackoverflow.com/questions/14245668/redirect-www-to-non-www-or-the-other-way-around