2

I am currently trying to build 301 redirect module in sitecore9.trying to receive requested URL .will be verifying in the content tree if requested URL has redirect URL then redirect to the URL with status code 301

Class:

public class RedirectProcessor : HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        if (Sitecore.Context.Item == null)
        {
            var requestedUrl = HttpContext.Current.Request.Url.ToString();
            var requestedPath = HttpContext.Current.Request.Url.AbsolutePath;
            var requestedPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            var db = Sitecore.Context.Database;

Sitecore config:

<processor type="Website.Foundation.Redirect.RedirectProcessor" patch:instead="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>

I am getting an error page after Sitecore login. I am not sure using ItemResolver is correct or not. what is the pipeline have to used for customizing rendering pipeline

1
  • Downloaded the sitecore 9 URL Rewrite package.is it possible to redirect OLD website URL to the new site. for example old Url: www.abc.com/care/overview/speck to www.abc.com/care/speck/overview Any documentation for this module is available? Aug 3, 2018 at 18:50

1 Answer 1

4

In your configuration, you are overwriting (patch:instead) the Sitecore processor (ItemResolver) responsible for figuring out the context item based on the HTTP request. If you remove that, not much is going to work.

Since your logic applies only when no such context item has been found, your processor should run after (patch:after) the item resolver, like so:

<processor type="Website.Foundation.Redirect.RedirectProcessor"
    patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>

I would add that handling redirections in this way can become surprisingly complex and can drastically impact performance if caching is not properly leveraged. If you have many such redirections, you might consider the use of an existing module such as the excellent URL Rewrite by Andy Cohen.

Update: There is a fork of this project for Sitecore 9, in which the author was kind enough to provide an updated package.

2
  • Thanks.URL Rewrite module is not supporting Sitecore 9 .after installing module package my instance is broken.
    – sindu
    Aug 3, 2018 at 18:03
  • You might want to try with this fork (package here).
    – maz
    Aug 3, 2018 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.