How to Redirect an Old URL to Another Page on Your Site

DNN > How To
How to Redirect an Old URL to Another Page on Your Site.

If you would like to redirect an old URL to another page on your site for SEO or SSL reasons you may do so by using the steps below. The redirect as configured below is a permanent, or 301, redirect.

In order to redirect individual pages to another page on your site, your site must be located on server meeting the minimum requirements of Server 2008 and IIS7
.  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.

If you intend to perform a large number of redirects, the instructions below may increase your web.config file to a size that is unable to be processed by IIS.  If this is the case you may split you web.config and rewrite rules in to two individual files to minimize the size of the web.config.  If you would like instructions on performing this option, please refer to our How to Configure Re-Write Rules Outside the Web.config article.
  1. Connect to your site's web.config file.  If you are unsure of how to do this please refer to our How to Access Your Web.Config article.
  2. Scroll down until you find the </handlers> line under <system.webServer>. Press enter after </handlers> to create a new line.
  3. Paste the following code at the new line, replacing [RULE NAME], [OLD URL] and [NEW URL] with the appropriate information (see Rule Variations below). Note: when putting in the [OLD URL], don't include the http:// as that will not work.
    <rewrite>
      <rules>
         <rule name="[RULE NAME]" stopProcessing="true">
         <match url="(.*)" />
         <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
            <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
            <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[OLD URL]" />
         </conditions>
         <action type="Redirect" url="http://[NEW URL]" redirectType="Permanent"/>
         </rule>
      </rules>
    </rewrite>
    • Note that redirectType="Permanent" can be changed to "Found" (302) or "Temporary" (307) depending on what type of redirect you need.
  4. Save the web.config
Rule Variations:

You can add additional rules by using multiple <rules></rules> tags as shown below.  Each rule must have it's own distinct rule name.
<rewrite>
  <rules>
     <rule name="[RULE NAME]" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[OLD URL]" />
     </conditions>
     <action type="Redirect" url="http://[NEW URL]" redirectType="Permanent"/>
     </rule>
     <rule name="[RULE NAME 2]" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
             <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[OLD URL]" />
     </conditions>
     <action type="Redirect" url="http://[NEW URL]" redirectType="Permanent"/>
     </rule>
  </rules>
</rewrite>
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.
<rewrite>
  <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]" redirectType="Permanent"/>
     </rule>
  </rules>
</rewrite>
 
If you need to redirect all pages of an old domain name to the same page on a new domain name you may do so using the rule below.
<rewrite>
  <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]/{R:1}" redirectType="Permanent"/>
     </rule>
  </rules>
</rewrite>

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

Add Feedback