Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 385
Gopinath Avatar asked Jul 19 '11 12:07

Gopinath


1 Answers

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.

like image 162
rtpHarry Avatar answered Oct 26 '22 10:10

rtpHarry