Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top works fine. gives 404 - File or directory not found.

I don't want people to use instead of, but I also don't want the 404 error in their face if the do.

The A record at GoDaddy looks like:
Host - Points to - TTL
@ - ip address - 600 seconds

How to fix the issue so that if user types in they would be magically redirected to

share|improve this question
up vote 2 down vote accepted

The solution to the problem was to have both domain names ( and explicitly set up in Azure as custom domains.

Then to use URL rewrite module in IIS (already installed in Azure) by adding rewrite section in the Web.config file:

    <clear />
    <rule name="WWW Rewrite" stopProcessing="true" enabled="true">
      <match url=".*" />
        <add input="{HTTP_HOST}" pattern="^www[.](.+)" />
      <action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
share|improve this answer
Could you expand on how this is done? "explicitly set up in Azure as custom domains" – IrishChieftain Feb 23 '13 at 13:49

I believe this is NOT a DNS job, you may make www as CNAME for but still, the www will show up in the URL

If you're using Apache2 or any webserver capable of reading and executing an .htaccess file you can use the code below :

<IfModule mod_rewrite.c>

# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /

# Add or remove www.  Whichever you prefer.
# This one removes which seems to be the favourable choice these days.
# ------------------------------
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

share|improve this answer
I do have CNAME for www, but get the error anyway. – z-boss Jan 21 '13 at 15:06
@Hicham, as stated in the subject, it is about Azure, which uses IIS and not Apache. – Tom Jan 21 '13 at 19:24
@Tom, I googled for that before giving my answer, ant nothing forces you to use IIS on Azure. At least, that is what I read when searching Azure .htaccess – cyberhicham Jan 21 '13 at 19:28
@Hicham, yes, you are right when you use, say, Linux with Apache on Azure Virtual Machines. However, Azure hosted website uses only IIS. – Tom Jan 21 '13 at 19:36
Fair enough, the OP will eventually tell us which environment he have ^^ – cyberhicham Jan 21 '13 at 21:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.