Link to home
Start Free TrialLog in
Avatar of Peter Nordberg
Peter NordbergFlag for Sweden

asked on

Re-direct in IIS

Hi,

I have a question if it's possible to re-direct (re-route) a web request in IIS. For example if a user enters www.mysite.com in the browser I would like it to end up in mysite.com.

Is this possible to do? I'm working in IIS on Windows Server 2012.

Thanks for help!

Peter
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Yes,

This should work:

<rule name="Remove www" stopProcessing="true">
  <match url="(.*)" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
  </conditions>
  <action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

Open in new window

Avatar of Peter Nordberg

ASKER

Hi and thanks for answer,

Where do I set this rule?

Peter
You can do this in the web.config in your application:


 <system.webServer>
  <rewrite>
      <rules>
       <!--  put <rule> -->
      </rules>
    </rewrite>
Hi,

I tried the rule but I got an internal server error. This is how I put it in my web.config:
 <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="2147483648"/>
        </requestFiltering>
      </security>
      <rewrite>
        <rules>
            <rule name="Remove www" stopProcessing="true">
          <match url="(.*)" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
          </conditions>
          <action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>
        </rules>
      
      </rewrite>
    </system.webServer>

Open in new window


What can be wrong?

Peter
I installed it and applied the rule again. This time I got no error but the redirect doesn't seem to take place. If I enter www.kanal10.se it doesn't rewrite it.

Thanks for help!

Peter
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Worked perfectly!

Peter