Azure
IISweb.config multiple url redirects

IIS web.config multiple url redirects

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
		<rule name="sub1.your.site" enabled="true" stopProcessing="true">
			<match url=".*" />
		<conditions>
			<add input="{HTTP_HOST}{REQUEST_URI}" pattern="sub1.your.site" ignoreCase="true" />
		</conditions>
			<action type="Redirect" url="https://www.wherever.com" redirectType="Permanent" appendQueryString="false" />
		</rule>
		<rule name="sub2.your.site" enabled="true" stopProcessing="true">
			<match url=".*" />
		<conditions>
			<add input="{HTTP_HOST}{REQUEST_URI}" pattern="sub2.your.site" ignoreCase="true" />
		</conditions>
			<action type="Redirect" url="https://www.wherever.com/this/time" redirectType="Permanent" appendQueryString="false" />
		</rule>
      </rules> 
    </rewrite>
  </system.webServer>
</configuration>  

Above is a code snippet from an IIS web.config file to demonstraight how to use an IIS site as a url redirection service. This example has 2 separate redirects but you can theoretically add as many as you need.

  • First point your required domain or sub domain to the IIS server
  • Add the domain to the bindings of the IIS Site
  • Add the above rules to your web.config file
  • Update the rule Name, Pattern and URL

Note: Make sure your rule names are unique as they won't work!