1

How do I get the naked domain for my site that is typed into a browser (example.com) to automatically redirect to www.mywebsite.com. Would this be done on the internal IIS web server or through the registration service DNS settings?

I use Register.com and I tried asking their technical support, but they did not answer my question with a usable solution.

  • 1
    You would use both: First create a DNS record for the www subdomain as covered in the second part of the answer here, then create a redirect rule for IIS as covered in this answer here. You can also do the later using a web.config file as William covered in his answer. – dan Aug 5 '14 at 1:00
  • Off topic, but may I ask why you chose register.com ? – Ring Ø Nov 6 '18 at 6:57
1

Would this be done on the internal IIS web server

It's possible. There are several ways. I will show the way where you use the web.config file. In your web.config file put the following code:

<rewrite>
    <rules>
    <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="domain.com" />
            </conditions>
            <action type="Redirect" url="http://www.domain.com/{R:0}" />
        </rule>
    </rules>
</rewrite>

Or if you want to use regular expressions:

<rewrite>
    <rules>
        <rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^domain.com$" />
            </conditions>
            <action type="Redirect" url="http://www.domain.com/{R:0}" />
        </rule>
    </rules>
</rewrite>
-1

Just try editing .htaccess file.

Just paste the following code in .htaccess file

#Force www:
 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^example.com [NC]
 RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

replace "example" with "your domain name".

  • 1
    The OP is asking about IIS, not Apache. – dan Aug 5 '14 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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