21 March 2018

Redirect Virtual Directory to External Website using URL Rewrite

I recently had a client with an externally facing IIS server using the Default Website, and multiple Virtual Directories.  They wanted everyone accessing one particular Virtual Directory to be redirected to a completely separate website.  The ultimate goal in mind was to ensure that only internal users connecting to http://hostname/virtualdirectory will have access to the page.

After look into the best way to make this work, I found that utilising URL Rewrite on their IIS server would give the best solution.

After replicating the setup in a test lab, I managed to get the URL Rewrite working, to only redirect to an external website when someone accessed http://subdomain.domain.com/virtualdirectory

The following config was entered into the web.config file for the specific Virtual Directory.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="External Redirect" stopProcessing="true">
        <match url="Test4" negate="true" />
        <conditions>
          <add input="{HTTP_HOST}" ignoreCase="true" negate="true" pattern="IIS"/>
        </conditions>
        <action type="Redirect" url="http://www.google.com.au" redirectType="Found" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

The items in bold require changing to match your specific IIS setup.  These are currently set to replicate my test lab environment.













When navigating to http://iis/test4, it loads the page.  When navigating to http://subdomain.domain.com/test4, it redirects to Google.  The setting is specific to the Virtual Directory, and other VDs are not affected by this.

3 comments:

  1. Casino Finder (Google Play) Reviews & Demos - Go
    Check Casino Finder (Google Play). A look at some หารายได้เสริม of 출장샵 the best authentic air jordan 14 shoes On sale gambling sites in 포커 족보 the world. They offer a 벳 365 full game library,

    ReplyDelete
  2. Whenever I put all these things on the testnet, I do not get the same result that I expect. Now I want you to look at https://www.academicinnovators.co.uk/ and tell me what's going on?

    ReplyDelete