In my controller BVZ\Customer\Controller\Index I'm doing a redirect using

return $this->_redirect('customer/index/firstAccess');

When the code execute, the request are made (see the print below) below enter image description here

but the url in browser stay in the same place.

how can i make the page redirect to 'customer/index/firstAccess' and not just make the request?

all code of my controller


namespace BVZ\Customer\Controller\Index;

class CustomerExists extends \Magento\Framework\App\Action\Action {

  public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
        \Magento\Customer\Api\AccountManagementInterface $customerAccountManagement
  ) {
            $this->resultJsonFactory = $resultJsonFactory;
            $this->customerAccountManagement = $customerAccountManagement;

  public function execute() {
    $cpfcpnj = $this->getRequest()->getParam('cpfcpnj');

    $vowels = array("-", ".","/");
    $cpfcpnj = str_replace($vowels, "", $cpfcpnj);

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
    $collection = $customerObj

  if($collection->getId()) {


          //email reset
          return $this->_redirect('customer/account/ResetPasswordPost');
          $return = "first";
      } else {
          $return = "exists";

  } else {
      $return = "new";

  $result = $this->resultJsonFactory->create();
  return $result->setData($return);
  • Hi, Please provide more information about your code and files to make it easier for everyone to understand the problem better. – Sarvagya Dec 19 '18 at 12:03
  • Hello, i have updated the question. Please check if became clearer. – Gabriel Fernandes Dec 19 '18 at 12:15
public function execute()
    $resultRedirect = $this->resultRedirectFactory->create();
    return $resultRedirect;
| improve this answer | |
  • This way it worked. I just needed to improve the AJAX, how the request was made via AJAX, the process redirect worked in php, but JS continued the process without counting this redirect. So I needed to set where I want to go in php and use another call in JS to redirect. – Gabriel Fernandes Dec 21 '18 at 10:44

Controller Result

Review this file: vendor/magento/framework/Controller/ResultFactory.php

Here is a sample of the ResultFactory usage:

// The use statement below is for constants. $this->resultFactory is inherited from parent class
use Magento\Framework\Controller\ResultFactory;

class Sample extends \Magento\Framework\App\Action\Action

    $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);

    $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);   

    /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    return $resultRedirect->setPath('*/*/');

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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