This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.
本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。
In the early days of the web it was imperative to publish your web address with a ‘www’ prefix. Those three characters prevented confusion; it was more obvious you meant a web domain.
在网络的早期,必须发布带有“ www”前缀的网址。 这三个字符防止了混乱; 很明显,您的意思是网络域名。
But is the ‘www’ necessary in 2017?
但是在2017年是否需要“ www”?
The web is prolific and few organizations opt to publish their URL with a preceding ‘www’. People understand that Google.com, Facebook.com, Twitter.com and SitePoint.com are websites. The dot-something top-level domain (TLD) such as ‘.com’ makes this more obvious but, even without it, the web is normally the first point of call for anyone looking for a company or service.
网络是多产的,很少有组织选择使用前面的“ www”来发布其URL。 人们了解Google.com,Facebook.com,Twitter.com和SitePoint.com是网站。 点状顶级域名(TLD)(例如“ .com”)使这一点变得更加明显,但是即使没有它,对于寻求公司或服务的任何人来说,网络通常也是他们的首要选择。
“ www”的案例 (The Case For ‘www’)
The ‘www’ prefix has not been deprecated. It’s unambiguous, technically accurate and distinguishes the address from similar URLs for protocols such as mail or FTP.
“ www”前缀尚未被弃用。 它是明确的,技术上准确的,并且将地址与类似邮件或FTP等协议的URL区别开来。
While a web address may be identifiable from it’s .com or country-specific prefix, hundreds of top-level domain options have been introduced in the past few years. If you’re using a less recognisable or ambiguous TLD, such as mysite.ninja, adding a ‘www’ will help avoid any doubt.
虽然可以通过.com或国家/地区前缀来识别网址,但在过去几年中引入了数百个顶级域选项。 如果您使用的是无法识别或模棱两可的TLD(例如mysite.ninja),则添加“ www”将有助于避免任何疑问。
Without the ‘www’, you must set your root (non-www) domain DNS A-record to point at your web server’s IP address. This can be too rigid if you encounter availability or performance issues; the A-record is fixed and can take a day or two for changes to propagate. A ‘www’ sub-domain can be configured using a DNS CNAME record which can be updated and changed instantly.
如果没有“ www”,则必须将根(非www)域DNS A记录设置为指向Web服务器的IP地址。 如果遇到可用性或性能问题,这可能会太死板; A记录是固定的,可能需要一两天才能传播更改。 可以使用DNS CNAME记录配置“ www”子域,该记录可以立即更新和更改。
You also need to be cautious of cookie and client-side storage. A cookie, sessionStorage, or localStorage value set for a non-www domain is shared throughout all sub-domains. If your primary website — mysite.com — sets 10Kb of cookie data, it’ll be transmitted with every request and response for app.mysite.com whether that application uses the data or not.
您还需要注意cookie和客户端存储。 在所有子域中共享为非www域设置的cookie,sessionStorage或localStorage值。 如果您的主要网站mysite.com设置了10Kb的cookie数据,则无论该应用程序是否使用该数据,都会随app.mysite.com的每个请求和响应一起传输。
Finally, the ‘www’ prefix is essential in applications such as email clients and word processors which transform text to links.
最后,“ www”前缀在将文本转换为链接的电子邮件客户端和文字处理器等应用程序中至关重要。
没有“ www”的情况 (The Case For No ‘www’)
Despite the technical issues raised above, using a non-www domain is rarely a problem unless you have complex hosting or application requirements. Root addresses are easier to read, quicker to type and fit easier in smaller (mobile) browser interfaces. The address is more likely to work your next tweet without having to use a URL shortener.
尽管上面提出了技术问题,但是除非您有复杂的托管或应用程序要求,否则使用非www域很少会成为问题。 根地址更易于阅读,键入速度更快,并且更适合在较小的(移动)浏览器界面中使用。 该地址更有可能在不使用URL缩短器的情况下处理您的下一条推文。
Few people will be confused — especially when many use the Google search box rather than the browser address bar.
很少有人会感到困惑-特别是当许多人使用Google搜索框而不是浏览器地址栏时。
这主要是虚荣的事情 (It’s Mostly a Vanity Thing)
Some domain names look better and more balanced with the ‘www’, e.g.
一些域名看起来更好,并且与“ www”更加平衡,例如
- www.google.com www.google.com
- www.facebook.com www.facebook.com
- www.bbc.co.uk www.bbc.co.uk
Some look better without:
有些看起来更好,但没有:
- twitter.com twitter.com
- yahoo.com yahoo.com
- wikipedia.org wikipedia.org
Some appear to work well in either orientation:
有些似乎在任一方向上都能很好地工作:
- sitepoint.com / www.sitepoint.com sitepoint.com / www.sitepoint.com
- amazon.com / www.amazon.com amazon.com/www.amazon.com
- dropbox.com / www.dropbox.com dropbox.com / www.dropbox.com
Choose whichever suits your domain but…
选择适合您的域的任何一个,但是…
明智地配置 (Configure It Wisely)
Users may or may not add a ‘www’ so ensure both the www and non-www address works when a browser request is made. This can be achieved in serveral ways but the easiest option can be a web server configuration setting.
用户可以添加也可以不添加“ www”,因此请确保在发出浏览器请求时,www和非www地址都可以使用。 这可以通过服务器方式实现,但是最简单的选项可以是Web服务器配置设置。
The following code in configures Apache to redirect all non-www requests to the www version of the URL. Add it to a .htaccess
file in your web root:
下面的代码将Apache配置为将所有非www请求重定向到URL的www版本。 将其添加到您的Web根目录中的.htaccess
文件中:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Alternatively, this .htaccess
redirects all www requests to the non-www URL:
另外,此.htaccess
会将所有www请求重定向到非www URL:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
This allows you to publicise the ‘www’ domain in documents or emails even if it’s not required.
这样,即使不需要,也可以在文档或电子邮件中公开“ www”域。
You should also be wary if your site is served over secure HTTPS. SSL certificates are often valid for both the non-www and www domain but there’s no guarantee. Check with your Certificate Authority — it may be necessary to purchase an additional or wildcard certificate if you have the wrong one. Some hosting providers, like our partner SiteGround, let you order an SSL certificate that will work with your domain with or without the www prefix.
如果您的网站是通过安全的HTTPS提供服务的,也应该保持警惕。 SSL证书通常对非www和www域都有效,但不能保证。 请与您的证书颁发机构核对-如果您有错误的证书,可能需要购买其他证书或通配符证书。 一些托管服务提供商,例如我们的合作伙伴SiteGround ,可以让您订购可以与您的域一起使用的SSL证书(带或不带www前缀)。
Finally, make a decision and stick with it. Never switch between non-www and www URLs on a whim! The .htaccess
code above issues a `301 Moved Permanently` HTTP redirect code so browsers and search engines update their indexes accordingly. It can take time for changes to disseminate; users could encounter access problems while that occurs.
最后,做出决定并坚持下去。 切勿一时兴起在非www和www URL之间切换! 上面的.htaccess
代码发布了“ 301永久移动” HTTP重定向代码,因此浏览器和搜索引擎会相应地更新其索引。 传播更改可能需要一些时间; 用户可能会遇到访问问题。
Did your company opt to use or drop the ‘www’? Was it a success? Did anyone notice?!
贵公司是否选择使用或删除“ www”? 成功了吗? 有人注意到吗?!