Solved

Re-direct in IIS

Posted on 2014-10-03
8
71 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
  • 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
 

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Recently, I was assigned the task of performing a hardware refresh in the datacenter. The previous Windows 2008 systems were connected to the SAN via fiber channel HBA’s and among other thing, had PowerPath installed in order to provide sufficient f…
The reason that corporations and businesses use Windows servers is because it supports custom modifications to adapt to the business and what it needs. Most individual users won’t need such powerful options. Here I’ll explain how you can enable Wind…
In this Micro Tutorial viewers will learn how to restore single file or folder from Bare Metal backup image of their system. Tutorial shows how to restore files and folders from system backup. Often it is not needed to restore entire system when onl…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now