0

I had hosted site in IIS which open in url like http://www.example.com as well as http://example.com but i dont want to open it in http://example.com , http://example.com might change to http://www.example.com Forcefully, what confugeration shoud i wright in web.config

manoj
  • 5,235
  • 7
  • 24
  • 45

1 Answers1

0

(Note: Updated answer below)

This requires you to make use of URL-rewriting.

This post here shows how to make use of the URL-Rewriting extensions:

http://www.dotnetexpertguide.com/2011/08/iis-7-redirect-domaincom-to.html

If you don't see this extension via IIS manager, you can download the extension here: http://www.iis.net/download/URLRewrite

You will want to add a rule, look under "search engine optimization" and edit "canonical domain name".

There you can direct all traffic to the www-version of the domain by selecting it in the dropdown.

EDIT: As for the question to do it in web.config, this is an example configuration:

<rewrite>
  <rules>
    <rule name="Redirect to www" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^domain.com$" />
      </conditions>
      <action type="Redirect" 
        url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
    </rule>
  </rules>
  <rewriteMaps>
    <rewriteMap name="MapProtocol">
      <add key="on" value="https" />
      <add key="off" value="http" />
    </rewriteMap>
  </rewriteMaps>
</rewrite>

Hope that helps,

Sebastian

sebomoto
  • 21
  • 3
  • is there any way to configure by writting some thing in web.config – manoj Sep 23 '14 at 08:01
  • Please see this related question, i think the answer can be applied in your case as well:[link](http://stackoverflow.com/questions/17714732/web-config-redirect-non-www-to-www) – sebomoto Sep 23 '14 at 08:10