XM Cloud offers two settings for redirects. Redirect Items, which operate on an item-by-item basis, and Redirect Map, which manages URLs related to redirects. These two are introduced in this article.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FZRE97z2n23yIu9C6p7TgB%2F42550094365168aa0b9a3d59c65ccb39%2Fnick-fewings-zF_pTLx_Dkg-unsplash.jpg&w=3840&q=75)
For more information on settings, the following official pages are helpful.
How redirects work
XM Cloud's sxastarter provides a redirection mechanism as Next.js middleware. And to use this redirection, simply create an item in the CMS.
- Redirect items - it is possible to place redirect items in the content tree and specify the destination.
- Redirect map - allows you to determine the URL to jump to by setting a rule that redirects instead of an item.
Base setting
As part of the redirection mechanism, the URL of the site must be included in the Target hostname in the site configuration by default.
![Redirects01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F3b3kEv7pKxdphHyK3eJ0QC%2F76cacc3cde4999b5f2a13421586c25e6%2FRedirects01.png&w=3840&q=75)
In this case, we will test the redirect by creating an item called Home/Success as the item to redirect to.
Creating redirects.
Redirect Item
Right-click on an item in the content tree in the content editor and a template for an item called Redirect appears as a candidate.
![Redirects02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1qXDfDRIUElrxmxWzyK2ld%2F602eaca746cf85e40038e73d8c7f9c95%2FRedirects02.png&w=3840&q=75)
This item is created, this time under Sample. As a redirect destination, the previously prepared Success item is selected.
![Redirects03.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5rGIZOgCbdJMiGBqfWnNCC%2F960935a77b84afe3862c5a9a22449c68%2FRedirects03.png&w=3840&q=75)
Publish the relevant item in the above form. When reflected,
- /Sample/RedirectTest path.
- /Redirect to Success page.
In this way, the redirect can work by setting the URL to jump to for the item in the relevant path. As a site, we have confirmed that it is possible to create an item and redirect as described above, where you have prepared a notice about the end of the page and when it is no longer valid, you will be redirected to that page.
Redirect Map
A redirect map is useful when you want to redirect a site according to some rules. When using this function, it is also possible to control the destination by preparing regular expressions.
Redirect maps can be found under the Redirects folder under Settings on the site, where there is a folder to store redirect maps and their items.
![Redirects04.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5NkM6I9SPpdO55PAvL4WKF%2F53b4d781ac7324e7b0e2c8daac2d62c2%2FRedirects04.png&w=3840&q=75)
The settings include the following items.
- Redirect type (301, 302 and transfer)
- Describes the rules for the old path (left column) and the new path (right column)
For example, the above redirection map could be used to ensure that the redirection is implemented even if the item has not been created.
Redirect maps are useful when you want to run redirects for a while when you delete old articles, as they can be processed collectively. By managing the rules as a single redirection map, it is possible to manage the rules in such a way that they can be deleted in the future when they are no longer needed.
Summary
This article provided a brief introduction to setting up redirects and creating items, and the difference between redirect maps and items.