Windows Azure: How to 301 non-www url to www for a domain

一笑奈何 提交于 2019-12-20 19:43:14

问题


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.

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?

Or is there any better way to 301 redirect all non-www urls to 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.com to www.coziie.com sorted out the issue.


回答1:


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.

update I 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).

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.

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.

Anyway, this is how I do it on an IIS7 server with the official url rewrite extension installed (this goes in your 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.




回答2:


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.

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.

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.




回答3:


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?



来源:https://stackoverflow.com/questions/6747007/windows-azure-how-to-301-non-www-url-to-www-for-a-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!