Constellation.Feature.Redirects is a library for addressing three common marketing needs:
- Creating 301 redirects from decommissioned URLs to currently active pages.
- Creating redirects from “marketing” URLs to deep content.
- Handling cases where an external URL needs to “look like” it’s local to page navigation, or where a single Sitecore hosted page needs to appear in two different areas of the site (as shown in navigation).
Sitecore has an older feature called Aliases that purports to address some of these requirements, but it has flaws:
- Not scalable beyond a few hundred URLs.
- Does not support “Permanent” redirects.
- Does not meet the needs of the third feature above.
What’s in the Box
Installing Constellation.Feature.Redirects gets you a new Sitecore “app” for the Sitecore Desktop called “Redirect Manager”. This application allows you to create, update, export, and import a list of marketing redirects.
You also get an Item Template that you can use to insert a “Page Redirect” anywhere in your content tree. This allows you to create “short” URLs that link to deeper content, or to host a URL within a given section of your site that points to something external to that branch of the content tree.
Using Redirect Manager
After installing this library, log into Sitecore and select “Desktop” from the Launchpad. Then, click the “start” button in the lower left hand corner. You should see a new icon in the start menu:
Click the icon to open the Redirect Manager.
Adding a New Marketing Redirect
To create a new Redirect, click the “New” icon in the toolbar of the Redirect Manager. You’ll be presented with the following dialog:
There are some rules associated with creating Marketing Redirects:
- All redirects in the system must be specific to one of the sites managed by Sitecore. The Site Name field contains a list of all sites in your Sitecore installation, you will have to specify one of these.
- The “Old URL” value must be a relative path, it cannot include a protocol or hostname. In the example above, /freeshirt is a relative path.
- The “Old URL” value must be unique to the current site. If you try to create a redirect that already exists, you will not be allowed to save your redirect.
- You can include file extensions and querystring parameters in the Old URL, but if you include file extensions, you need to ask your developers if they are supported. Example: /myfile.php?id=98667587
- The “New URL” value can be either a relative path to another Sitecore Item in your site (including Media Library Items or query parameters) or an absolute URL to any destination on the Internet. However, that URL must exist, must be published, and cannot be a redirect itself. All “New URL” values are validated and you will not be permitted to create a redirect to an invalid URL.
- Marketing Redirects are technically Sitecore Items and therefore you’ll need to run a publish job after you’re done inputting new redirects.
Editing Existing Redirects
If you need to adjust or delete an existing Marketing Redirect, select it from the table and press Edit or Delete. Pressing Edit will present a dialog that allows you to change the values for the Redirect. Pressing Delete will ask for confirmation before deleting the record. Note that deleted records can be restored using the Sitecore Recycle Bin if the Recycle Bin is enabled on your system.
Clear All, the Nuclear Option
Marketing Redirects get stale. Campaigns may be over, and 301 Redirects created for the benefit of Search Engines typically need to last only a month or two while search engines re-index your site. There will likely come a time where it is useful to clean house. Clear All will delete all of the Marketing Redirects in your system. You will be asked to confirm before this action occurs. We strongly recommend exporting your redirects before performing this action in case you have regrets.
Importing and Exporting Marketing Redirects
While we strongly recommend using the Redirect Manager within Sitecore to organize your redirects, it is possible to import your redirects using a Comma Delimited (*.csv) file. This file format is supported by Microsoft Excel.
Getting the *.csv File Format
The best way to create a valid file is to export one from the system. If you don’t have any redirects, create a “dummy” redirect and then choose Export from the toolbar. This will provide you with a *.csv file to edit and an example of the correct syntax.
Editing the *.csv File
Keep in mind that all the rules discussed above apply to your redirects.
- You must specify the site name, which is a very specific word. If you don’t know your site name, ask your developers.
- The redirect must be unique.
- The target of the redirect must exist or it will fail to import.
When you save the *.csv file, make sure you continue to save it as a “Comma Delimited” file, otherwise it will fail to import.
Importing the File
Importing is as simple as logging into Sitecore, launching the Redirect Manager and clicking Import. There will be a dialog that allows you to select a file off of your computer, along with a button to start the import process.
After the import process is complete, the system will provide you with a brief status report indicating:
- How many records it inspected.
- How many new records were created.
- If any duplicates were found.
- If any records with invalid targets were found.
- If any records failed to import due to a bad “Old URL” value.
Marketing Redirects are not live immediately after creation. To deploy, you must run a site-wide publish. If your developer team has installed a regular background publishing job, your redirects will be published along with other content.
Redirect Manager Notes for Developers
Redirect Manager is written on the (now ancient) Sitecore Sheer UI API. It will likely be discontinued in a future version of Sitecore. Redirect Items are stored in an Item Bucket located at:
They can be managed as native Sitecore Items, although the following features are not available:
- The “Site Name” field is not a drop-down, but a Single Line Text Field.
- Site Name field is not validated.
- Old URL field is not validated.
- New URL field is not validated.
- Import and Export features are not available
For this reason we strongly recommend against editing Items directly through the Item Bucket interface.
The Site Name Field
The list of options in this field is driven from the SiteInfo objects available via:
It makes some assumptions about how you have structured Sitecore:
- Each “site” in your installation must have a <site/> element in the Sitecore configuration files.
- Ideally each “site” should have its own hostname.
- The “targetHostName” attribute of every non-system <site/> element is populated with a valid value.
- The “scheme” attribute of every non-system <site/> element is populated with a valid value (http or https at time of writing)
- No user-maintained site in the installation should use the “website” site node.
- Virtual Folders are supported, but not recommended.
If a site does not show up in the available Site Names list within the Redirect Manager, chances are it violates one of the assumptions listed here.
Constellation.Feature.Redirects also installs a small Item Template that you can use to allow Marketers to put redirects that are interspersed with your site’s pages. The Item Template includes an Item Controller that handles the redirect when the Item’s URL is requested. The Template also has a dedicated “Navigation Title” field to use when the Page Redirect type Item must appear in local navigation.
To use, add the following Item Template as an insert option to Page Items on your site:
Constellation.Feature.Redirects is managed via NuGet.
In Visual Studio, fire up the Package Manager console and install into a Web Application project:
PM:> Install-Package Constellation.Feature.Redirects
After installation, it’s very important that you build and deploy your solution. You must then immediately run your Sitecore install to make sure the attached Items get added to your databases.
Start creating redirects! You can also check out the source code available on GitHub.
A big Thank You to Verndale who provided the Sheer UI implementation and some of the core concepts for this module.