I recently worked on a website migration. This invovled migrating from http to https and changing to a new URL structure.
Simple redirect rules using regular expression couldn’t be used as pages sitting under the same URL structure were being migrqted to a different format.

The option was to map the entire website: from old new url to the new corresponding one and implement redirects at a URL level.
The easiest way to handle many URLs is to use a RewriteMap (this is also available with IIS see below)

RewriteMap works with a dbm map which is generated from a text file which should look like this

 
my-old-uri new-uri
old-folder/old-rui new-folder/new-uri

  
In order to generated your dbm map you need to run the following command:

 
httxt2dbm -i /etc/apache/redirect-map.txt -o /etc/apache/redirect-map.db

  
Once your dbm map has been generate you can update your htaccess with the following

 
RewriteEngine On
RewriteMap redirects dbm=db: /etc/apache/redirect-map.db
RewriteCond {redirects:$1} !=""
RewriteRule ^/(.*)/(.*)/(.*)$ http://www.domain.com/(.*)/${redirects:$1}/$2? [R=permanent,L]

  

Handling multiple redirections with IIS
IIS servers also allow the usage of RewriteMap in a very similar way.
First the rewritemap should follow this structure

 
<rewriteMaps>  
  <rewriteMap name="Redirects">  
    <add key="/my-old-uri" value="/my-new-uri" />  
    <add key="/my-second-old-uri" value="/my-second-new-uri" />  
  </rewriteMap>  
</rewriteMaps>  

  
RewriteMaps allow you to have multiple sets of maps if you need to apply specific rules or conditions to your URLs (redirectings static pages, dynamic pages, articles etc etc)

 
<rewriteMaps>  
  <rewriteMap name="RedirectsSet1">  
    <add key="/my-old-uri" value="/my-new-uri" />  
    <add key="/my-second-old-uri" value="/my-second-new-uri" />  
  </rewriteMap>  
  <rewriteMap name="RedirectsSet2">  
    <add key="/my-old-article" value="/my-new-article" />  
    <add key="/my-second-old-article" value="/my-second-new-article" />  
  </rewriteMap>  
</rewriteMaps>  

  
Once all the URLs are listed save your file as rewritemaps.config in he same directory as your web.config file.
You then need to add the follow line to your web.config file

 
<rewriteMaps configSource="rewritemaps.config" />

  
And this what the final file should look like

 
  <rewrite>  
    <rewriteMaps configSource="rewritemaps.config">><rewriteMaps>  
    <rules>  
      <rule name="Redirect Set 1">  
        <match url=".*" />  
        <conditions>  
          <add input="{	RedirectsSet1:{REQUEST_URI}}" pattern="(.+)" />  
        </conditions>  
        <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />  
      </rule>  
      <rule name="Redirect Set 2">  
        <match url=".*" />  
        <conditions>  
          <add input="{RedirectsSet2:{REQUEST_URI}}" pattern="(.+)" />  
        </conditions>  
        <action type="Redirect" url="{C:1}" appendQueryString="false"  redirectType="Permanent" />  
      </rule>  
    </rules>  
  </rewrite>
 

  

Handling large amounts of redirections using this method should make it easier and faster server-side wise. Once your redirections are implement and your test environment, make sure you test them using a crawler such as Screaming frog. This will ensure redirects are working properly

Leave a Reply

Your email address will not be published. Required fields are marked *