URL Rewrite Module for Sitecore, part 1
When the content of a page has expired or it is not relevant anymore, and a new version is available in a different URL, it is common that the web administrator creates rules so the old URL redirects to the new content URL.
One IIS module used to do this task is the IIS URL Rewrite which allows creating rules to generate URLs that can be easier for users to remember, simple for search engines to index, allow URLs to follow a consistent and canonical hostname format, and also redirect to a new URL.
However, the rules have to be created in the web.config file, which means that the web administrator cannot create or modify a rule without restarting the application instance.
Fortunately for Sitecore applications, there is a module available in the marketplace that allows creating the same rules that can be created with the IIS URL Rewrite module, its name is URL Rewrite Module. With this module, you can create the following rules:
- Simple Redirect
Allows you to specify a regular expression match condition and a redirect target URL. It will always use a 301 redirect set to not cache. - Inbound Rule
Allows you to set a regular expression to match on the path of a URL. Supports regular expression capture groups the same way that IIS UrlRewrite module does.
Installation
Download the module from the downloads section of the URL Rewrite Module page. Then, install the module using the Installation Wizard. Finally, publish the /sitecore/system/Modules/Url Rewrite item, be sure you select Publish subitems and P**ublish related items.
Usage
Once the module is installed, there is a folder in the Sitecore/Content/ level which contains some rewrite items.
Simple redirect creation
To create a simple redirect, right click at a folder where you want to create the rewrite rule and select Simple Redirect.
Then, modify the Path and Target fields. The Target link can be an internal or external resource.
Then, save it and publish it. Once it is published, if the user visits the http://sc800/developer path (sc800 is the domain name of the local instance used for this example), the request will be redirected to https://dev.sitecore.net.
Constraints
- The paths added in the IgnoreUrlPrefixes setting of Sitecore are also ignored by this module. This means, for instance, if the IgnoreUrlPrefixes setting has a value like /sitecore/, and the path you set is “sitecore”, then it would not be redirected.
In the next post, I will show how to create more complex and different rules using Inbound Rules.
That’s it for today.
Until the next post!