Import redirects for 404 handler

Frederik Vig 11/2/2016 8:06:00 PM

Often we receive a spreadsheet of URLs from our customers with old URLs and where they should go to in the new site. These can easily be imported into the 404 handler module, but they need to be converted into a specific XML format first before importing.

Example:

<redirects>
<urls>
<url>
<!--
This redirects within the same site.
-->
<old>/templates/page.aspx?id=1234</old>
<new>/travel</new>
</url>
<url>
<!--
This redirects to an old server.
-->
<old>/mytemplates/form.aspx?id=3453</old>
<new>http://www2.mysite.no/page13241.php</new>
</url>
<url>
<!--
Several out-dated urls can be redirected
to the same new url.
-->
<old>/extra/ecp</old>
<old>/extra/eec</old>
<old>/templates/ecb.aspx?id=7556</old>
<new>/wehavemoved</new>
</url>
<url>
<!--
Old shortcut url to
new shortcut url!
-->
<old>/oldshortcuturl</old>
<new>/newshortcuturl</new>
</url>
<url>
<!-- Test to check that this should not
go into a infinite loop -->
<old>/demo1/notfoundtest</old>
<new>/demo1/notfoundtest</new>
</url>
<url>
<!-- You can also use site relative roots
for your destination, as the redirect
is done on the server.
-->
<old>/demo1/templates/Page.aspx?id=7411111</old>
<new>~/search</new>
</url>
<url>
<!-- Usually, when a "beginning of string" match is found, the path
and querystring of the old url is appended to the new one. This
can be used to redirect all pages below a given path to an old
server. If you do not want the string beeing appended, set the
onWildCardMatchSkipAppend to true.
-->
<old onWildCardMatchSkipAppend="true">/our_business/markets/transport</old>
<new>/en/Our-business/Markets/Automotive-and-transport/</new>
</url>
</urls>
</redirects>

Source: https://www.coderesort.com/p/epicode/wiki/404Handler/DocCms5#Custom404HandlerCMS4and5.

Creating the XML

For the Excel spreadsheet we can use string concatenation to create the XML in Excel.

="<url><old>"&A33&"</old><new>"&B33&"</new></url>"

Save it in an XML file and then import it through the 404 handler Gadget (you need to add the gadget called custom redirect manager to the dashboard):

Click the little configuration wheel in the bottom right corner and Administer.

Here you'll see different options, including exporting the redirects, what we're interested in is the import functionality.

Click Import redirects from an XML-file, choose the XML file with the redirects and click Import.

Note: If the import fails, take a look at the Episerver log file for more details. Usually there is some invalid XML characters involved. It's helpful to validate the XML before importing it. Another common error is duplicate keys (duplicate old URLs).

And that's it, thanks to the BV Network team for creating this awesome module.