apache 一个站点的多个域:别名还是重定向?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/139889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple domains for one site: alias or redirect?
提问by Jonah Braun
I'm setting up a number sites right now and many of them have multiple domains. The question is: do I alias the domain (with ServerAlias) or do I Redirectthe request?
我现在正在建立多个站点,其中许多站点都有多个域。问题是:我是给域取别名(使用ServerAlias)还是重定向请求?
Obviously ServerAlias is better/easier from a readability or scripting perspective. I have heard however that Google likes it better if everything redirects to one domain. Is this true? If so, what redirect code should be used?
显然,从可读性或脚本的角度来看,ServerAlias 更好/更容易。然而,我听说如果一切都重定向到一个域,Google 会更喜欢它。这是真的?如果是这样,应该使用什么重定向代码?
Common vhost examples will have:
常见的虚拟主机示例将有:
ServerName example.net
ServerAlias www.example.net
Is this wrong and should the www also be a redirect in addition to example2.net and www.example2.net? Or is Google smart enough to that all these sites (or at least the www) are the same site?
这是错误的,除了 example2.net 和 www.example2.net 之外,www 是否也应该是重定向?或者 Google 是否足够聪明,以至于所有这些站点(或至少 www)都是同一个站点?
UPDATE: Part of the reasoning for wanting aliases is that they are much faster. A redirect for a dialup user just because they did (or didn't) use the www adds significantly to initial page load.
更新:想要别名的部分原因是它们要快得多。仅仅因为拨号用户使用(或没有)使用 www 就为拨号用户重定向显着增加了初始页面加载。
UPDATE and ANSWER: Thanks Paul for finding the Google linkwhich instructs us to "help your fellow webmasters by notperpetuating the myth of duplicate content penalties". Note, however, this only applies to content ON THE SAME SITE, exemplified in the article with "www.example.com/skates.asp?color=black&brand=riedell or www.example.com/skates.asp?brand=riedell&color=black". In fact, the article explicitly says "Don't create multiple pages, subdomains, or domains with substantially duplicate content."
更新和回答:感谢 Paul 找到Google 链接,该链接指示我们“通过不延续重复内容处罚的神话来帮助您的网站管理员”。但是请注意,这仅适用于同一站点上的内容,在文章中举例说明了“www.example.com/skates.asp?color=black&brand=riedell 或 www.example.com/skates.asp?brand=riedell&color=黑色的”。事实上,文章明确指出“不要创建多个页面、子域或包含大量重复内容的域”。
回答by Paul Dixon
Redirecting is better, then there is always one, canonical domain for your content. I hear Google penalises multiple domains hosting the same content, but I can't find a source for that at the moment (edit, here's one article, but from 2005, which is ancient history in Internet years!)(not correct, see edit below)
重定向更好,那么您的内容总会有一个规范域。我听说 Google 会惩罚托管相同内容的多个域,但我目前找不到来源(编辑,这里是一篇文章,但从 2005 年开始,这是互联网时代的古老历史!)(不正确,请参阅编辑以下)
Here's some mod-rewrite rules to redirect to a canonical domain:
以下是一些重定向到规范域的 mod-rewrite 规则:
RewriteCond %{HTTP_HOST} !^www\.foobar\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.foobar.com/ [L,R=permanent]
That checks that the host isn't the canonical domain (www.foobar.com) and checks that a domain has actually been specified, before deciding to redirect the request to the canonical domain.
在决定将请求重定向到规范域之前,它会检查主机是否不是规范域 (www.foobar.com) 并检查域是否已实际指定。
Further Edit: Here's an article straight from the horses mouth- seems it's not as big an issue as you might think. Please read this article CAREFULLY as it distinguishes between duplicate content on the same site (as in "www.example.com/skates.asp?color=black&brand=riedell and www.example.com/skates.asp?brand=riedell&color=black") and specifically says "Don't create multiple pages, subdomains, or domains with substantially duplicate content."
进一步编辑:这是一篇直接来自马口的文章-似乎这不是您想象的那么大的问题。请仔细阅读本文,因为它区分了同一站点上的重复内容(如“www.example.com/skates.asp?color=black&brand=riedell 和 www.example.com/skates.asp?brand=riedell&color=black ") 并特别说明“不要创建多个页面、子域或包含大量重复内容的域。”
回答by micahwittman
SSL certificates can also be an issue (wild card certs mitigate this but are more expensive).
SSL 证书也可能是一个问题(通配符证书可以缓解这一问题,但价格更高)。
So if the cert is only bound to www.example.com, it won't validate for example.com. If this circumstance applies to your case, then carefully handling, redirects and hyperlink references in your html and javascript is very important.
因此,如果证书仅绑定到 www.example.com,则它不会针对 example.com 进行验证。如果这种情况适用于您的情况,那么在您的 html 和 javascript 中仔细处理、重定向和超链接引用非常重要。
回答by Adam Hughes
If they are entirely different domain names, you will want to redirect because otherwise cookies can not be shared between the two. If a user logs into your website at example1.com, they will need to log in again if they visit example2.com.
如果它们是完全不同的域名,您将需要重定向,否则 cookie 无法在两者之间共享。如果用户通过 example1.com 登录您的网站,则他们在访问 example2.com 时需要再次登录。
If they are just different subdomains (example.com vs www.example.com) this won't matter.
如果它们只是不同的子域(example.com 与 www.example.com),这无关紧要。
回答by moonshadow
Server aliasing can cause problems with CGI session continuity: since cookies are attached to the domain they were served from, CGI scripts have to be carefully written so that they are aware of the aliasing, or all links within and into the site have to be relative, or both - it is much harder to avoid niggly little hard-to-debug problems due to the browser serving you different cookies based on whether the user last entered your site through name.tld or www.name.tld.
服务器别名可能会导致 CGI 会话连续性问题:由于 cookie 附加到提供它们的域,因此必须仔细编写 CGI 脚本,以便它们知道别名,或者站点内和进入站点的所有链接都必须是相对的,或两者兼而有之 - 由于浏览器根据用户上次是通过 name.tld 还是 www.name.tld 访问您的站点,为您提供不同的 cookie,因此很难避免一些棘手的难以调试的问题。
回答by Rich Bradshaw
Nowadays I doubt it matters. If you see both entries in google, then you know you're doing it wrong.
现在我怀疑这很重要。如果您在 google 中看到这两个条目,那么您就知道自己做错了。
回答by Mark Ransom
If half the links to your site refer to one URL and half refer to another, each URL is only going to get half the pagerank. Even if Google doesn't penalize your rank for having duplicate content, you're going to suffer.
如果您网站的一半链接指向一个 URL,另一半指向另一个 URL,则每个 URL 只会获得一半的 pagerank。即使谷歌不会因为你的内容重复而惩罚你的排名,你也会受苦。

