Windows Azure:如何将域的 301 非 www url 转为 www
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6747007/
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
Windows Azure: How to 301 non-www url to www for a domain
提问by Gopinath
I recently deployed an Windows Azure application and configured DNS of my domain through DreamHost portal. Now my site is accessible through http://www.coziie.com, but not through non-www address.
我最近部署了一个 Windows Azure 应用程序并通过 DreamHost 门户配置了我的域的 DNS。现在我的网站可以通过http://www.coziie.com 访问,但不能通过非 www 地址访问。
I read in one of the articles that I should add an A record in DNS settings and point to virutal IP of Windows Azure. How do I get virutal IP of my Windows Azure deployment?
我在其中一篇文章中读到我应该在 DNS 设置中添加 A 记录并指向 Windows Azure 的虚拟 IP。如何获得我的 Windows Azure 部署的虚拟 IP?
Or is there any better way to 301 redirect all non-www urls to www?
或者有没有更好的方法来 301 将所有非 www 网址重定向到 www?
RESOLVED: I was able to solve this problem by simple configuring a website redirect settings in DreamHost DNS settings. A simple 301 redirect of http://coziie.comto www.coziie.com sorted out the issue.
已解决:我能够通过简单的配置在DreamHost的DNS设置的网站重定向设置来解决这个问题。一个简单的http://coziie.com到 www.coziie.com 的301 重定向就解决了这个问题。
回答by rtpHarry
You are talking about two separate issues here.
你在这里谈论两个不同的问题。
The first is to setup a DNS record so that your un-canonised url works. The second is to redirect the url if the site is accessed by it.
第一个是设置 DNS 记录,以便您的非规范化 url 工作。第二个是重定向 url,如果该站点被它访问。
updateI have removed the previous advice for CNAME from here as I didn't realise before that you cannot set the root domain to a CNAME record. It seems that with the ip restrictions of Azure you will have to point the root domain record at non-azure, asp.net hosting and then put a 301 redirect (such as the one further down my reply) to forward it on to the Azure domain (www domain).
更新我已经从这里删除了以前对 CNAME 的建议,因为我之前没有意识到您不能将根域设置为 CNAME 记录。似乎有了 Azure 的 ip 限制,您必须将根域记录指向非 azure、asp.net 托管,然后进行 301 重定向(例如我回复中的进一步)以将其转发到 Azure域(www 域)。
When you have http://coziie.com/pointing at your site and serving the page its then time to fix this because Google can get confused, think its two different sites and then dilute your page rank between the two.
当您将http://coziie.com/指向您的站点并提供页面时,是时候解决这个问题了,因为 Google 可能会感到困惑,认为它是两个不同的站点,然后在两者之间稀释您的页面排名。
The trick is to set up a 301 redirect. I believe the url rewriting tool started out as an addon for IIS7 but is now included in it? You might have to do a quick search on that.
诀窍是设置 301 重定向。我相信 url 重写工具最初是作为 IIS7 的插件,但现在包含在其中?您可能需要对此进行快速搜索。
Anyway, this is how I do it on an IIS7 server with the official url rewrite extension installed (this goes in your web.config):
无论如何,这就是我在安装了官方 url 重写扩展的 IIS7 服务器上执行此操作的方式(这在您的 web.config 中):
<system.webServer>
<rewrite>
<rules>
<clear/>
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\."/>
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Intellisense will complain that its not a recognised element but thats just a cosmetic issue while you are editing the file.
Intellisense 会抱怨它不是一个可识别的元素,而这只是您编辑文件时的外观问题。
回答by dunnry
The VIP address is easily obtained by either looking at the portal (read deployment details) or by simply pinging your .cloudapp.net address. You can set an A record, but you must be prepared to update that in case you delete your deployment. Once you delete a deployment, the VIP address will be returned to the pool and there is pretty much a guarantee that you will get a new VIP address on the next deploy.
通过查看门户(阅读部署详细信息)或简单地 ping 您的 .cloudapp.net 地址,可以轻松获得 VIP 地址。您可以设置 A 记录,但您必须准备好在删除部署时更新该记录。删除部署后,VIP 地址将返回到池中,并且几乎可以保证您将在下次部署时获得新的 VIP 地址。
You can maintain your VIP address by using the Upgrade feature as opposed to new deployments. There are some limitations to this, but it works for updates that do not change the Service Definition broadly speaking.
您可以使用升级功能而不是新部署来维护您的 VIP 地址。对此有一些限制,但它适用于不会从广义上改变服务定义的更新。
We used to say that the VIP address was not guaranteed even if you did an update, but MS has come back with stronger language about guarantees. See here.
我们过去常说,即使您进行了更新,也无法保证 VIP 地址,但是 MS 以更强的语言来保证。 见这里。
回答by dunnry
CNAMES are only for subdomains, like sub.example.com or www.example.com, you can't register a CNAME for example.com in other words. If your domain provider supports it you could create a redirect from example.com to www.example.com and then create a CNAME record for www.example.com, the CNAME will match www.example.com against example.cloudapp.net. My domain provider has a web console where I can do this easily, perhaps yours have too?
CNAMES 仅用于子域,例如 sub.example.com 或 www.example.com,换句话说,您不能为 example.com 注册 CNAME。如果您的域提供商支持它,您可以创建从 example.com 到 www.example.com 的重定向,然后为 www.example.com 创建 CNAME 记录,CNAME 会将 www.example.com 与 example.cloudapp.net 匹配。我的域提供商有一个 Web 控制台,我可以在其中轻松完成此操作,也许您的也有?