How to Configure Re-Write Rules Outside the Web.config

DNN > How To
How to Configure Re-Write Rules Outside the Web.config

If you intend to perform a large number of redirects from old URLs to new URLs on your site you may split your web.config and rewrite rules into two individual files to minimize the size of the web.config following the steps below.

In order to redirect individual pages to another page on your site, your site must be located on a server running Server 2008 and IIS7 or better.  If your site is hosted on a server running on an older environment, or are unsure of the environment your site is hosted on, please open a ticket with our Support department to discuss additional options.

Create the Pointer to the ReWrite Rules File.
  1. Connect to your site's web.config file.  See How to Access Your Web.Config.
  2. Scroll down until you find the </handlers> line under <system.webServer> and press enter to add a new line.
  3. Paste the following code at the new line
    <rewrite>
          <rules configSource="rewriteRules.config" />
    </rewrite>
  4. Save the web.config

Create the ReWrite Rules File.

  1. On your local computer create a new text document and save it as RewriteRules.config.
  2. At the top of the ReWriteRules.config file you have just created paste the following code, replacing [RULE NAME], [OLD URL] and [NEW URL] with the appropriate information. Note: when putting in the [OLD URL], don't include the http:// as that will not work.
    <rules>
      <rule name="[RULE NAME]" stopProcessing="true">
         <match url="(.*)" />
         <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
            <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
         </conditions>
         <action type="Redirect" url="http://[NEW URL]" />
      </rule>
    </rules>
  3. Save the ReWriteRules.config file.
  4. Connect to your site files using FTP.  See How to Use FTP.
  5. Upload your new ReWriteRules.config file to your httpdocs folder.
  6. Restart your site's application pool.  Refer to How to Recycle a Website's IIS Application Pool in Our Environment if needed.

Note:

You can add additional rules by using multiple <rules></rules> tags as shown below.  Each rule must have it's own distinct rule name.
 

<rules>
  <rule name="[RULE NAME]" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
     </conditions>
     <action type="Redirect" url="http://[NEW URL]" />
  </rule>
     <rule name="[RULE NAME 2]" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
     </conditions>
     <action type="Redirect" url="http://[NEW URL]" />
  </rule>
</rules>
 

 

If you are trying to redirect multiple old URLs to a new common URL, you may do this with a single rule as shown below.
 

<rules>
  <rule name="[RULE NAME]" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL 1]" />
     <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL 2]" />
     <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL 3]" />
     </conditions>
     <action type="Redirect" url="http://[NEW URL]" />
  </rule>
</rules>

When you browse to the old URL, you will now get redirected to the new URL.

 

Add Feedback