How to redirect page to 404 in magento2?












0














I want to redirect sales/order/history page to 404 in magento2.










share|improve this question
























  • Add the URL to index.php to get 404 not found
    – PMPD
    yesterday










  • Can it possible by url rewrite?
    – Rutvee Sojitra
    yesterday










  • You can redirect using .htaccess too.
    – Vivek
    yesterday












  • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
    – Minesh Patel
    yesterday


















0














I want to redirect sales/order/history page to 404 in magento2.










share|improve this question
























  • Add the URL to index.php to get 404 not found
    – PMPD
    yesterday










  • Can it possible by url rewrite?
    – Rutvee Sojitra
    yesterday










  • You can redirect using .htaccess too.
    – Vivek
    yesterday












  • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
    – Minesh Patel
    yesterday
















0












0








0







I want to redirect sales/order/history page to 404 in magento2.










share|improve this question















I want to redirect sales/order/history page to 404 in magento2.







magento2 404-page






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









PMPD

979




979










asked yesterday









Rutvee SojitraRutvee Sojitra

1,4071121




1,4071121












  • Add the URL to index.php to get 404 not found
    – PMPD
    yesterday










  • Can it possible by url rewrite?
    – Rutvee Sojitra
    yesterday










  • You can redirect using .htaccess too.
    – Vivek
    yesterday












  • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
    – Minesh Patel
    yesterday




















  • Add the URL to index.php to get 404 not found
    – PMPD
    yesterday










  • Can it possible by url rewrite?
    – Rutvee Sojitra
    yesterday










  • You can redirect using .htaccess too.
    – Vivek
    yesterday












  • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
    – Minesh Patel
    yesterday


















Add the URL to index.php to get 404 not found
– PMPD
yesterday




Add the URL to index.php to get 404 not found
– PMPD
yesterday












Can it possible by url rewrite?
– Rutvee Sojitra
yesterday




Can it possible by url rewrite?
– Rutvee Sojitra
yesterday












You can redirect using .htaccess too.
– Vivek
yesterday






You can redirect using .htaccess too.
– Vivek
yesterday














you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
– Minesh Patel
yesterday






you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
– Minesh Patel
yesterday












3 Answers
3






active

oldest

votes


















1














You can do using plugin.



Create around method on execute() over class MagentoSalesControllerOrderHistory and redirect to 404 page.



Plugin Class



<?php
namespace StackexchangeTestPlugin;


class HistoryPlugin
{
/**
* @var MagentoFrameworkAppActionContext
*/
private $context;
private $response;
private $redirect;
/**
* @var MagentoFrameworkUrlInterface
*/
private $url;


public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkUrlInterface $url
)
{
$this->context = $context;
$this->response = $context->getResponse();
$this->redirect = $context->getRedirect();

$this->url = $url;
}

public function aroundExecute(
MagentoSalesControllerOrderHistory $object,
callable $proceed
){

$norouteUrl = $this->url->getUrl('noroute');
$this->getResponse()->setRedirect($norouteUrl);
return;
}
/**
* Retrieve response object
*
* @return MagentoFrameworkAppResponseInterface
*/
public function getResponse()
{
return $this->response;
}
}





share|improve this answer























  • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
    – Minesh Patel
    yesterday










  • it will not work ? why it require code if funcnality is already there ?
    – Minesh Patel
    yesterday



















2














Create di.xml file



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoSalesControllerOrderHistory">
<plugin name="YourPluginName" type="VendorModulePluginOrderHistory" />
</type>
</config>


Create the plugin file



<?php

namespace VendorModulePluginOrder;

class History
{
private $context;
private $url;

public function __construct(
MagentoFrameworkAppActionContext $context,
) {
$this->resultRedirectFactory = $context->getResultRedirectFactory();
$this->resultFactory = $context->getResultFactory();
$this->url = $url;
}

public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
{
$returnValue = $proceed();
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
$norouteUrl = $this->url->getUrl('noroute');
$result = $resultRedirect->setUrl($norouteUrl);
return $result;
}
}





share|improve this answer































    0














    Hope this will help you.



    You need to add the following code in di.xml



    <type name="MagentoSalesControllerOrderHistory">
    <plugin name="YourPluginOrderHistory"
    type="VendorModulePluginOrderHistory"
    sortOrder="10"
    disabled="false"/>
    </type>


    Then you need to add the following code in VendorModulePluginOrderHistory
    History.php



    <?php

    namespace VendorModulePluginOrder;
    use MagentoFrameworkExceptionNotFoundException;
    class History
    {
    public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
    {
    $returnValue = $proceed();
    // your custom code after the original execute function
    if ($returnValue) {
    throw new NotFoundException(__('Parameter is incorrect.'));
    }

    return $returnValue;
    }
    }
    ?>


    Thanks






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "479"
      };
      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257052%2fhow-to-redirect-page-to-404-in-magento2%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can do using plugin.



      Create around method on execute() over class MagentoSalesControllerOrderHistory and redirect to 404 page.



      Plugin Class



      <?php
      namespace StackexchangeTestPlugin;


      class HistoryPlugin
      {
      /**
      * @var MagentoFrameworkAppActionContext
      */
      private $context;
      private $response;
      private $redirect;
      /**
      * @var MagentoFrameworkUrlInterface
      */
      private $url;


      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkUrlInterface $url
      )
      {
      $this->context = $context;
      $this->response = $context->getResponse();
      $this->redirect = $context->getRedirect();

      $this->url = $url;
      }

      public function aroundExecute(
      MagentoSalesControllerOrderHistory $object,
      callable $proceed
      ){

      $norouteUrl = $this->url->getUrl('noroute');
      $this->getResponse()->setRedirect($norouteUrl);
      return;
      }
      /**
      * Retrieve response object
      *
      * @return MagentoFrameworkAppResponseInterface
      */
      public function getResponse()
      {
      return $this->response;
      }
      }





      share|improve this answer























      • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
        – Minesh Patel
        yesterday










      • it will not work ? why it require code if funcnality is already there ?
        – Minesh Patel
        yesterday
















      1














      You can do using plugin.



      Create around method on execute() over class MagentoSalesControllerOrderHistory and redirect to 404 page.



      Plugin Class



      <?php
      namespace StackexchangeTestPlugin;


      class HistoryPlugin
      {
      /**
      * @var MagentoFrameworkAppActionContext
      */
      private $context;
      private $response;
      private $redirect;
      /**
      * @var MagentoFrameworkUrlInterface
      */
      private $url;


      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkUrlInterface $url
      )
      {
      $this->context = $context;
      $this->response = $context->getResponse();
      $this->redirect = $context->getRedirect();

      $this->url = $url;
      }

      public function aroundExecute(
      MagentoSalesControllerOrderHistory $object,
      callable $proceed
      ){

      $norouteUrl = $this->url->getUrl('noroute');
      $this->getResponse()->setRedirect($norouteUrl);
      return;
      }
      /**
      * Retrieve response object
      *
      * @return MagentoFrameworkAppResponseInterface
      */
      public function getResponse()
      {
      return $this->response;
      }
      }





      share|improve this answer























      • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
        – Minesh Patel
        yesterday










      • it will not work ? why it require code if funcnality is already there ?
        – Minesh Patel
        yesterday














      1












      1








      1






      You can do using plugin.



      Create around method on execute() over class MagentoSalesControllerOrderHistory and redirect to 404 page.



      Plugin Class



      <?php
      namespace StackexchangeTestPlugin;


      class HistoryPlugin
      {
      /**
      * @var MagentoFrameworkAppActionContext
      */
      private $context;
      private $response;
      private $redirect;
      /**
      * @var MagentoFrameworkUrlInterface
      */
      private $url;


      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkUrlInterface $url
      )
      {
      $this->context = $context;
      $this->response = $context->getResponse();
      $this->redirect = $context->getRedirect();

      $this->url = $url;
      }

      public function aroundExecute(
      MagentoSalesControllerOrderHistory $object,
      callable $proceed
      ){

      $norouteUrl = $this->url->getUrl('noroute');
      $this->getResponse()->setRedirect($norouteUrl);
      return;
      }
      /**
      * Retrieve response object
      *
      * @return MagentoFrameworkAppResponseInterface
      */
      public function getResponse()
      {
      return $this->response;
      }
      }





      share|improve this answer














      You can do using plugin.



      Create around method on execute() over class MagentoSalesControllerOrderHistory and redirect to 404 page.



      Plugin Class



      <?php
      namespace StackexchangeTestPlugin;


      class HistoryPlugin
      {
      /**
      * @var MagentoFrameworkAppActionContext
      */
      private $context;
      private $response;
      private $redirect;
      /**
      * @var MagentoFrameworkUrlInterface
      */
      private $url;


      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkUrlInterface $url
      )
      {
      $this->context = $context;
      $this->response = $context->getResponse();
      $this->redirect = $context->getRedirect();

      $this->url = $url;
      }

      public function aroundExecute(
      MagentoSalesControllerOrderHistory $object,
      callable $proceed
      ){

      $norouteUrl = $this->url->getUrl('noroute');
      $this->getResponse()->setRedirect($norouteUrl);
      return;
      }
      /**
      * Retrieve response object
      *
      * @return MagentoFrameworkAppResponseInterface
      */
      public function getResponse()
      {
      return $this->response;
      }
      }






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited yesterday

























      answered yesterday









      Amit BeraAmit Bera

      57.3k1474170




      57.3k1474170












      • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
        – Minesh Patel
        yesterday










      • it will not work ? why it require code if funcnality is already there ?
        – Minesh Patel
        yesterday


















      • you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
        – Minesh Patel
        yesterday










      • it will not work ? why it require code if funcnality is already there ?
        – Minesh Patel
        yesterday
















      you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
      – Minesh Patel
      yesterday




      you can add in default URL rewrite as custom url(Admin Panel Menu Marketing ->SEO & Search ->URL Rewrites )
      – Minesh Patel
      yesterday












      it will not work ? why it require code if funcnality is already there ?
      – Minesh Patel
      yesterday




      it will not work ? why it require code if funcnality is already there ?
      – Minesh Patel
      yesterday













      2














      Create di.xml file



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoSalesControllerOrderHistory">
      <plugin name="YourPluginName" type="VendorModulePluginOrderHistory" />
      </type>
      </config>


      Create the plugin file



      <?php

      namespace VendorModulePluginOrder;

      class History
      {
      private $context;
      private $url;

      public function __construct(
      MagentoFrameworkAppActionContext $context,
      ) {
      $this->resultRedirectFactory = $context->getResultRedirectFactory();
      $this->resultFactory = $context->getResultFactory();
      $this->url = $url;
      }

      public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
      {
      $returnValue = $proceed();
      $resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
      $norouteUrl = $this->url->getUrl('noroute');
      $result = $resultRedirect->setUrl($norouteUrl);
      return $result;
      }
      }





      share|improve this answer




























        2














        Create di.xml file



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoSalesControllerOrderHistory">
        <plugin name="YourPluginName" type="VendorModulePluginOrderHistory" />
        </type>
        </config>


        Create the plugin file



        <?php

        namespace VendorModulePluginOrder;

        class History
        {
        private $context;
        private $url;

        public function __construct(
        MagentoFrameworkAppActionContext $context,
        ) {
        $this->resultRedirectFactory = $context->getResultRedirectFactory();
        $this->resultFactory = $context->getResultFactory();
        $this->url = $url;
        }

        public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
        {
        $returnValue = $proceed();
        $resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
        $norouteUrl = $this->url->getUrl('noroute');
        $result = $resultRedirect->setUrl($norouteUrl);
        return $result;
        }
        }





        share|improve this answer


























          2












          2








          2






          Create di.xml file



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoSalesControllerOrderHistory">
          <plugin name="YourPluginName" type="VendorModulePluginOrderHistory" />
          </type>
          </config>


          Create the plugin file



          <?php

          namespace VendorModulePluginOrder;

          class History
          {
          private $context;
          private $url;

          public function __construct(
          MagentoFrameworkAppActionContext $context,
          ) {
          $this->resultRedirectFactory = $context->getResultRedirectFactory();
          $this->resultFactory = $context->getResultFactory();
          $this->url = $url;
          }

          public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
          {
          $returnValue = $proceed();
          $resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
          $norouteUrl = $this->url->getUrl('noroute');
          $result = $resultRedirect->setUrl($norouteUrl);
          return $result;
          }
          }





          share|improve this answer














          Create di.xml file



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoSalesControllerOrderHistory">
          <plugin name="YourPluginName" type="VendorModulePluginOrderHistory" />
          </type>
          </config>


          Create the plugin file



          <?php

          namespace VendorModulePluginOrder;

          class History
          {
          private $context;
          private $url;

          public function __construct(
          MagentoFrameworkAppActionContext $context,
          ) {
          $this->resultRedirectFactory = $context->getResultRedirectFactory();
          $this->resultFactory = $context->getResultFactory();
          $this->url = $url;
          }

          public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
          {
          $returnValue = $proceed();
          $resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
          $norouteUrl = $this->url->getUrl('noroute');
          $result = $resultRedirect->setUrl($norouteUrl);
          return $result;
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          Rohan HapaniRohan Hapani

          1




          1























              0














              Hope this will help you.



              You need to add the following code in di.xml



              <type name="MagentoSalesControllerOrderHistory">
              <plugin name="YourPluginOrderHistory"
              type="VendorModulePluginOrderHistory"
              sortOrder="10"
              disabled="false"/>
              </type>


              Then you need to add the following code in VendorModulePluginOrderHistory
              History.php



              <?php

              namespace VendorModulePluginOrder;
              use MagentoFrameworkExceptionNotFoundException;
              class History
              {
              public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
              {
              $returnValue = $proceed();
              // your custom code after the original execute function
              if ($returnValue) {
              throw new NotFoundException(__('Parameter is incorrect.'));
              }

              return $returnValue;
              }
              }
              ?>


              Thanks






              share|improve this answer


























                0














                Hope this will help you.



                You need to add the following code in di.xml



                <type name="MagentoSalesControllerOrderHistory">
                <plugin name="YourPluginOrderHistory"
                type="VendorModulePluginOrderHistory"
                sortOrder="10"
                disabled="false"/>
                </type>


                Then you need to add the following code in VendorModulePluginOrderHistory
                History.php



                <?php

                namespace VendorModulePluginOrder;
                use MagentoFrameworkExceptionNotFoundException;
                class History
                {
                public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
                {
                $returnValue = $proceed();
                // your custom code after the original execute function
                if ($returnValue) {
                throw new NotFoundException(__('Parameter is incorrect.'));
                }

                return $returnValue;
                }
                }
                ?>


                Thanks






                share|improve this answer
























                  0












                  0








                  0






                  Hope this will help you.



                  You need to add the following code in di.xml



                  <type name="MagentoSalesControllerOrderHistory">
                  <plugin name="YourPluginOrderHistory"
                  type="VendorModulePluginOrderHistory"
                  sortOrder="10"
                  disabled="false"/>
                  </type>


                  Then you need to add the following code in VendorModulePluginOrderHistory
                  History.php



                  <?php

                  namespace VendorModulePluginOrder;
                  use MagentoFrameworkExceptionNotFoundException;
                  class History
                  {
                  public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
                  {
                  $returnValue = $proceed();
                  // your custom code after the original execute function
                  if ($returnValue) {
                  throw new NotFoundException(__('Parameter is incorrect.'));
                  }

                  return $returnValue;
                  }
                  }
                  ?>


                  Thanks






                  share|improve this answer












                  Hope this will help you.



                  You need to add the following code in di.xml



                  <type name="MagentoSalesControllerOrderHistory">
                  <plugin name="YourPluginOrderHistory"
                  type="VendorModulePluginOrderHistory"
                  sortOrder="10"
                  disabled="false"/>
                  </type>


                  Then you need to add the following code in VendorModulePluginOrderHistory
                  History.php



                  <?php

                  namespace VendorModulePluginOrder;
                  use MagentoFrameworkExceptionNotFoundException;
                  class History
                  {
                  public function aroundExecute(MagentoSalesControllerOrderHistory $subject, Closure $proceed)
                  {
                  $returnValue = $proceed();
                  // your custom code after the original execute function
                  if ($returnValue) {
                  throw new NotFoundException(__('Parameter is incorrect.'));
                  }

                  return $returnValue;
                  }
                  }
                  ?>


                  Thanks







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  ShankarShankar

                  355




                  355






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257052%2fhow-to-redirect-page-to-404-in-magento2%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      An IMO inspired problem

                      Management

                      Has there ever been an instance of an active nuclear power plant within or near a war zone?