Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
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 at 1:00

2 Answers 2

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>
share|improve this answer

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".

share|improve this answer
1  
The OP is asking about IIS, not Apache. –  dan Aug 5 at 22:01

Your Answer

 
discard

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.