Replacing 404 errors with 410 Sitecore 7.2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












This may be a little broad so I'd appreciate any pointers.



Is there a way to replace the typical 404 response with 410 for pages that have been deleted? Obviously I'd like to keep 404 responses for genuine 404's.



Thanks.










share|improve this question









New contributor




Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    This may be a little broad so I'd appreciate any pointers.



    Is there a way to replace the typical 404 response with 410 for pages that have been deleted? Obviously I'd like to keep 404 responses for genuine 404's.



    Thanks.










    share|improve this question









    New contributor




    Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      This may be a little broad so I'd appreciate any pointers.



      Is there a way to replace the typical 404 response with 410 for pages that have been deleted? Obviously I'd like to keep 404 responses for genuine 404's.



      Thanks.










      share|improve this question









      New contributor




      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      This may be a little broad so I'd appreciate any pointers.



      Is there a way to replace the typical 404 response with 410 for pages that have been deleted? Obviously I'd like to keep 404 responses for genuine 404's.



      Thanks.







      pipelines error-handling






      share|improve this question









      New contributor




      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 22 mins ago









      Dan Sinclair

      537314




      537314






      New contributor




      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Sean T

      1085




      1085




      New contributor




      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Sean T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          You certainly could, but it requires a couple moving parts:



          Track the pages when they are deleted so you can look them up later



          To know whether a requested URL used to exist or not, you'll need to track pages as they're deleted so you can check that list later.



          You'll need an item:deleted event handler:



          public class PageDeletionLogger

          public void ItemDeleted(object sender, EventArgs args)




          (And you'll need this handy template checking method [beware: it's recursive]):



          public static class TemplateExtensions

          public static bool IsDerived([NotNull]this Template template, [NotNull]ID templateId)




          And you'll need to patch it into config:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <events>
          <event name="item:deleted">
          <handler type="Custom.Events.PageDeletionLogger,Custom" method="ItemDeleted" />
          </event>
          </events>
          </sitecore>
          </configuration>


          Look them up as part of the HttpRequestBegin pipeline



          Then, when incoming requests are processed, you'll need to look them up in your list of deleted pages and see whether they should get a 410 or 404.



          public class DeletedPageResolver : HttpRequestProcessor

          public override void Process(HttpRequestArgs args)

          // If we resolved a context item, get out
          if (Sitecore.Context.Item != null)
          return;

          var listOfDeletedPageUrls = // TODO: Get the list of deleted page URLs
          if (listOfDeletedPageUrls.Contains(args.Context.Request.RawUrl))

          // TODO: Set your 410 HTTP status code





          And, of course, you'll need to patch that into config, too:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <pipelines>
          <httpRequestBegin>
          <processor type="Custom.Processors.HttpRequestBegin.DeletedPageResolver, Custom" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
          </httpRequestBegin>
          </pipelines>
          </sitecore>
          </configuration>


          Disclaimer



          I've not worked with the 410 status code before, so it's possible you'll need to do more to avoid having the page redirect to an error page (e.g. resolve the Sitecore.Context.Item to a page that has the 410 error content you want to display).






          share|improve this answer




















          • Superb, thanks a lot - this is far more than I had hoped for.
            – Sean T
            2 hours ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "664"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Sean T is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14449%2freplacing-404-errors-with-410-sitecore-7-2%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote



          accepted










          You certainly could, but it requires a couple moving parts:



          Track the pages when they are deleted so you can look them up later



          To know whether a requested URL used to exist or not, you'll need to track pages as they're deleted so you can check that list later.



          You'll need an item:deleted event handler:



          public class PageDeletionLogger

          public void ItemDeleted(object sender, EventArgs args)




          (And you'll need this handy template checking method [beware: it's recursive]):



          public static class TemplateExtensions

          public static bool IsDerived([NotNull]this Template template, [NotNull]ID templateId)




          And you'll need to patch it into config:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <events>
          <event name="item:deleted">
          <handler type="Custom.Events.PageDeletionLogger,Custom" method="ItemDeleted" />
          </event>
          </events>
          </sitecore>
          </configuration>


          Look them up as part of the HttpRequestBegin pipeline



          Then, when incoming requests are processed, you'll need to look them up in your list of deleted pages and see whether they should get a 410 or 404.



          public class DeletedPageResolver : HttpRequestProcessor

          public override void Process(HttpRequestArgs args)

          // If we resolved a context item, get out
          if (Sitecore.Context.Item != null)
          return;

          var listOfDeletedPageUrls = // TODO: Get the list of deleted page URLs
          if (listOfDeletedPageUrls.Contains(args.Context.Request.RawUrl))

          // TODO: Set your 410 HTTP status code





          And, of course, you'll need to patch that into config, too:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <pipelines>
          <httpRequestBegin>
          <processor type="Custom.Processors.HttpRequestBegin.DeletedPageResolver, Custom" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
          </httpRequestBegin>
          </pipelines>
          </sitecore>
          </configuration>


          Disclaimer



          I've not worked with the 410 status code before, so it's possible you'll need to do more to avoid having the page redirect to an error page (e.g. resolve the Sitecore.Context.Item to a page that has the 410 error content you want to display).






          share|improve this answer




















          • Superb, thanks a lot - this is far more than I had hoped for.
            – Sean T
            2 hours ago














          up vote
          5
          down vote



          accepted










          You certainly could, but it requires a couple moving parts:



          Track the pages when they are deleted so you can look them up later



          To know whether a requested URL used to exist or not, you'll need to track pages as they're deleted so you can check that list later.



          You'll need an item:deleted event handler:



          public class PageDeletionLogger

          public void ItemDeleted(object sender, EventArgs args)




          (And you'll need this handy template checking method [beware: it's recursive]):



          public static class TemplateExtensions

          public static bool IsDerived([NotNull]this Template template, [NotNull]ID templateId)




          And you'll need to patch it into config:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <events>
          <event name="item:deleted">
          <handler type="Custom.Events.PageDeletionLogger,Custom" method="ItemDeleted" />
          </event>
          </events>
          </sitecore>
          </configuration>


          Look them up as part of the HttpRequestBegin pipeline



          Then, when incoming requests are processed, you'll need to look them up in your list of deleted pages and see whether they should get a 410 or 404.



          public class DeletedPageResolver : HttpRequestProcessor

          public override void Process(HttpRequestArgs args)

          // If we resolved a context item, get out
          if (Sitecore.Context.Item != null)
          return;

          var listOfDeletedPageUrls = // TODO: Get the list of deleted page URLs
          if (listOfDeletedPageUrls.Contains(args.Context.Request.RawUrl))

          // TODO: Set your 410 HTTP status code





          And, of course, you'll need to patch that into config, too:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <pipelines>
          <httpRequestBegin>
          <processor type="Custom.Processors.HttpRequestBegin.DeletedPageResolver, Custom" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
          </httpRequestBegin>
          </pipelines>
          </sitecore>
          </configuration>


          Disclaimer



          I've not worked with the 410 status code before, so it's possible you'll need to do more to avoid having the page redirect to an error page (e.g. resolve the Sitecore.Context.Item to a page that has the 410 error content you want to display).






          share|improve this answer




















          • Superb, thanks a lot - this is far more than I had hoped for.
            – Sean T
            2 hours ago












          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          You certainly could, but it requires a couple moving parts:



          Track the pages when they are deleted so you can look them up later



          To know whether a requested URL used to exist or not, you'll need to track pages as they're deleted so you can check that list later.



          You'll need an item:deleted event handler:



          public class PageDeletionLogger

          public void ItemDeleted(object sender, EventArgs args)




          (And you'll need this handy template checking method [beware: it's recursive]):



          public static class TemplateExtensions

          public static bool IsDerived([NotNull]this Template template, [NotNull]ID templateId)




          And you'll need to patch it into config:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <events>
          <event name="item:deleted">
          <handler type="Custom.Events.PageDeletionLogger,Custom" method="ItemDeleted" />
          </event>
          </events>
          </sitecore>
          </configuration>


          Look them up as part of the HttpRequestBegin pipeline



          Then, when incoming requests are processed, you'll need to look them up in your list of deleted pages and see whether they should get a 410 or 404.



          public class DeletedPageResolver : HttpRequestProcessor

          public override void Process(HttpRequestArgs args)

          // If we resolved a context item, get out
          if (Sitecore.Context.Item != null)
          return;

          var listOfDeletedPageUrls = // TODO: Get the list of deleted page URLs
          if (listOfDeletedPageUrls.Contains(args.Context.Request.RawUrl))

          // TODO: Set your 410 HTTP status code





          And, of course, you'll need to patch that into config, too:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <pipelines>
          <httpRequestBegin>
          <processor type="Custom.Processors.HttpRequestBegin.DeletedPageResolver, Custom" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
          </httpRequestBegin>
          </pipelines>
          </sitecore>
          </configuration>


          Disclaimer



          I've not worked with the 410 status code before, so it's possible you'll need to do more to avoid having the page redirect to an error page (e.g. resolve the Sitecore.Context.Item to a page that has the 410 error content you want to display).






          share|improve this answer












          You certainly could, but it requires a couple moving parts:



          Track the pages when they are deleted so you can look them up later



          To know whether a requested URL used to exist or not, you'll need to track pages as they're deleted so you can check that list later.



          You'll need an item:deleted event handler:



          public class PageDeletionLogger

          public void ItemDeleted(object sender, EventArgs args)




          (And you'll need this handy template checking method [beware: it's recursive]):



          public static class TemplateExtensions

          public static bool IsDerived([NotNull]this Template template, [NotNull]ID templateId)




          And you'll need to patch it into config:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <events>
          <event name="item:deleted">
          <handler type="Custom.Events.PageDeletionLogger,Custom" method="ItemDeleted" />
          </event>
          </events>
          </sitecore>
          </configuration>


          Look them up as part of the HttpRequestBegin pipeline



          Then, when incoming requests are processed, you'll need to look them up in your list of deleted pages and see whether they should get a 410 or 404.



          public class DeletedPageResolver : HttpRequestProcessor

          public override void Process(HttpRequestArgs args)

          // If we resolved a context item, get out
          if (Sitecore.Context.Item != null)
          return;

          var listOfDeletedPageUrls = // TODO: Get the list of deleted page URLs
          if (listOfDeletedPageUrls.Contains(args.Context.Request.RawUrl))

          // TODO: Set your 410 HTTP status code





          And, of course, you'll need to patch that into config, too:



          <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
          <sitecore>
          <pipelines>
          <httpRequestBegin>
          <processor type="Custom.Processors.HttpRequestBegin.DeletedPageResolver, Custom" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
          </httpRequestBegin>
          </pipelines>
          </sitecore>
          </configuration>


          Disclaimer



          I've not worked with the 410 status code before, so it's possible you'll need to do more to avoid having the page redirect to an error page (e.g. resolve the Sitecore.Context.Item to a page that has the 410 error content you want to display).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          Dan Sinclair

          537314




          537314











          • Superb, thanks a lot - this is far more than I had hoped for.
            – Sean T
            2 hours ago
















          • Superb, thanks a lot - this is far more than I had hoped for.
            – Sean T
            2 hours ago















          Superb, thanks a lot - this is far more than I had hoped for.
          – Sean T
          2 hours ago




          Superb, thanks a lot - this is far more than I had hoped for.
          – Sean T
          2 hours ago










          Sean T is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Sean T is a new contributor. Be nice, and check out our Code of Conduct.












          Sean T is a new contributor. Be nice, and check out our Code of Conduct.











          Sean T is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14449%2freplacing-404-errors-with-410-sitecore-7-2%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery