Creating a redirect rule

Overview

A redirect rule enables more than one URL to point to a single Web page.

 

Step-by-Step Guide

  1. Go to the IIS Manager.
  2. Select your site.
  3. In the Feature view, click URL Rewrite.
    • If you don't see the URL Rewrite module, you can download it from here.
  4. In the Actions pane, on the right side, click on Add rules 
  5. Select the Blank Rule template. 
  6. The Edit Inbound Rule screen will open so you can customize the redirection rule. 
  7. You can follow this article, in order to have a better understanding of how to create the rules.

This is stored on an XML file called web.config, you can also edit that file and set up the rule on an XML format. Such as:

<rule name="Spanish Redirect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="website.es" />
</conditions>
<action type="Redirect" url="https://website.com/es/{R:0}" redirectType="Permanent" />
</rule></rule>

Custom Redirect Rules

 Redirecting from a path to a subdomain

  • From any page in www.domain.com/Path1
  • To http://www.path.domain.com/
<rule name="Path to Subdomain" stopProcessing="true">
      <match url=".*" />
      <conditions>
          <add input="{HTTP_HOST}" pattern="www.domain.com" />
          <add input="{PATH_INFO}" pattern="/Path1.*" />
      </conditions>
      <action type="Redirect" url="http://www.path.domain.com/" />
</rule>

Redirecting from a domain except for certain paths

  • From any page in www.domain.com
    • Except for www.domain.com/Path1
  • To https://www.anotherdomain.com/
<rule name="All except Path to Another Domain" stopProcessing="true">
      <match url=".*" />
      <conditions>
          <add input="{HTTP_HOST}" pattern="www.domain.com" />
          <add input="{PATH_INFO}" pattern="/(Path1).*" negate="true" />
      </conditions>
      <action type="Redirect" url="https://www.anotherdomain.com/" />
</rule>

 

For more information about the XML and how could you change it, please go to this link.

 

Content Author: Manuel Gonzales

Comments

0 comments

Please sign in to leave a comment.