?
Solved

Re-direct in IIS

Posted on 2014-10-03
8
Medium Priority
?
75 Views
Last Modified: 2014-10-12
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
0
Comment
Question by:peternordberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40359901
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

0
 

Author Comment

by:peternordberg
ID: 40359926
Hi and thanks for answer,

Where do I set this rule?

Peter
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40360150
You can do this in the web.config in your application:


 <system.webServer>
  <rewrite>
      <rules>
       <!--  put <rule> -->
      </rules>
    </rewrite>
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:peternordberg
ID: 40366412
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
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40366628
Do you have the re-write module installed on the server?  

http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
0
 

Author Comment

by:peternordberg
ID: 40366708
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
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 40368639
Here are some screen shots:
http://www.serverintellect.com/support/iis/url-rewrite-to-redirect-www-iis7/

From there it seems like I may have been off in the pattern match:
<system.webServer>
         <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

0
 

Author Closing Comment

by:peternordberg
ID: 40376412
Thanks. Worked perfectly!

Peter
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
A procedure for exporting installed hotfix details of remote computers using powershell
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question