Please create a web.config file in your root directory if it's not already there. And then put the following code into your web.config file.
1: 301 redirect domain.com to www.domain.com
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
configuration
>
<
system.webServer
>
<
rewrite
>
<
rules
>
<
rule
name
=
"Canonical Host Name"
stopProcessing
=
"true"
>
<
match
url
=
"(.*)"
/>
<
conditions
>
<
add
input
=
"{HTTP_HOST}"
pattern
=
"^domain\.com$"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"http://www.domain.com/{R:0}"
redirectType
=
"Permanent"
/>
</
rule
>
</
rules
>
</
rewrite
>
</
system.webServer
>
</
configuration
>
2: 301 redirect all domains to one domain name
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
configuration
>
<
system.webServer
>
<
rewrite
>
<
rules
>
<
rule
name
=
"Enforce canonical hostname"
stopProcessing
=
"true"
>
<
match
url
=
"(.*)"
/>
<
conditions
>
<
add
input
=
"{HTTP_HOST}"
negate
=
"true"
pattern
=
"^www\.domain\.com$"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"http://www.domain.com/{R:0}"
redirectType
=
"Permanent"
/>
</
rule
>
</
rules
>
</
rewrite
>
</
system.webServer
>
</
configuration
>