Search code examples
asp.netiisweb-configurl-rewritingwindows-server-2012

URL forwarding within a web config file for Windows Server 2012 IIS 8.5


I am trying to forward a specific URL on my website to another website and I can't figure out how to set the proper values in the web.config file for my IIS server.

For example I would like to forward www.example.com/ballot to ballot.example.com

So far I've tried the following but it doesn't have any affect to the url

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^/ballot$" ignoreCase="false" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^example\.com$" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://ballot.example.com/" />
    </rule>
  </rules>
</rewrite>

I'm hosting the website on a Rackspace Cloud site.


Solution

  • Okay, I figured this one out and I'm posting the solution here for anyone else that may come across a similar situation.

    If you want to redirect a certain URL like http://www.example.com/ballot to http://ballot.example.com/

    Then follow these steps

    1. If one doesn't already exist create a directory called ballot directly under the web root of www.example.com.

    2. Create a Web.config file and place it in the ballot directory with the following content.

    3. Make sure you change the destination to your actual destination.

    4. If you are hosting on a Rackspace cloudsite you must rebuild the application (not sure about other host). You can rebuild the application by deleting the Web.Config file (if one was present) and uploading a new one, or by clicking the rebuild application link within the General Settings tab of the cloudsite you are trying to redirect. More information about rebuild applications in Rackspace here: http://www.rackspace.com/knowledge_center/article/how-to-rebuild-an-aspnet-application-in-cloud-sites.

    Also here is a link to the page where I ultimately found the solution to what I was trying to accomplish: https://www.stokia.com/support/misc/web-config-response-redirect.aspx