Solved

Re-direct in IIS

Posted on 2014-10-03
8
73 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Understanding the various editions available is vital when you decide to purchase Windows Server 2012. You need to have a basic understanding of the features and limitations in each edition in order to make a well-informed decision that best suits y…
Resolve DNS query failed errors for Exchange
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

696 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