Solved

Re-direct in IIS

Posted on 2014-10-03
8
69 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 39

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 39

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 39

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 39

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

In my previous 24 VMware Articles (http://www.experts-exchange.com/ARTH_1864316.html?arthOrderBy=3&arthSort=1#arth), most featured Intermediate VMware Topics. My next series of articles concentrated on topics for the VMware Novice;   If you would…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this Micro Tutorial viewers will learn how they can get their files copied out from their unbootable system without need to use recovery services. As an example non-bootable Windows 2012R2 installation is used which has boot problems.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

705 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

19 Experts available now in Live!

Get 1:1 Help Now