IIS Folder to Folder Redirect Rule

Occasionally, it may be necessary to set up a redirect from a folder on your site to access files on a different site.  For example, www.yourdomain.com/music/somerandomfile.mp3 redirecting to www.someotherdomain/someStorageAccount/MyMusicStuff/somerandomfile.mp3.  Now, we could set up a redirect rule for each file - but that could be a lot of rules, and lots of rules would slow down the site load times.  Instead, we can set up a single rule to redirect the folder and keep the file name.
If you'd like to redirect an entire folder to a different location, just follow the directions below!
  • Navigate to the httpdocs folder via FTP
  • Create a backup copy of your web.config
  • Open your web.config in a text editor, preferably Notepad++
  • Scroll down to just below the </handlers> tag
  • Add the following code snippet directly below that tag, but make sure you aren't adding a second set of <rewrite> tags or <rules> tags!  If you are, just copy the rest of the code to inside the current ones.
Caution!  Adding multiple <rewrite> or <rules> tag set or placing this code in the wrong location will cause the site to generate internal server errors, making it unavailable for visitors until the additional tags are removed.
        <rule name="NAME" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}{REQUEST_URI}" pattern="(.*)/FOLDER/(.*)" />
            <action type="Redirect" appendQueryString="false" url="http://DESTINATION-URL.TLD/FOLDERS/{C:2}" redirectType="Permanent" />
  • Change the bolded pieces of code to fit your needs.
    • NAME can be anything, as long as it is unique
    • /FOLDER/ is the folder you are redirecting from
    • http://DESTINATION-URL.TLD/FOLDERS/ is where you are redirecting to.
  • Save the changes to the web.config, this will cause the application pool to restart and the site may be unavailable for a few seconds.  If this causes a 500 error, something has gone wrong with the changes and you should either fix the error or revert to the backup.
If you have any trouble setting up this redirect rule, you can always contact our support team.  We'd be happy to assist you in this matter, and we're available 24/7.

Add Feedback