title: Redirect customer to product page from where customer logged in to website Magento 2
body: <p>In Magento 2, I have a custom login form in Header.  </p>
  
  <p>If a customer is on the product page for eg : </p>
  
  <p><a href="http://www.testwebsite.com/catalog/product/view/id/10" rel="nofollow noreferrer">http://www.testwebsite.com/catalog/product/view/id/10</a></p>
  
  <p>and login from header form then customer should redirect to the same product page instead of Customer Dashboard.</p>
  
  <p>I have tried plugin code from this <a href="https://magento.stackexchange.com/questions/134808/magento-2-redirect-customer-to-custom-page-after-login">link</a>. </p>
  
  <p>Below is my custom header form code - </p>
  
  <pre><code>&lt;?php 
  
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
  $customerSession = $objectManager-&gt;get('Magento\Customer\Model\Session'); 
  
  $urlInterface = \Magento\Framework\App\ObjectManager::getInstance()-&gt;get('Magento\Framework\UrlInterface');
  $currenturl =  $urlInterface-&gt;getCurrentUrl();
  
  if(!$customerSession-&gt;isLoggedIn()) {?&gt;
  &lt;div class="header-login-main"&gt;
      &lt;form action="&lt;?php echo $this-&gt;getUrl('customer/account/loginPost');?&gt;" method="post" id="login-form" novalidate="novalidate"&gt;
          &lt;input name="form_key" value="" type="hidden"&gt;
          &lt;div class="header-login" style=""&gt;
              &lt;span&gt;Email&lt;/span&gt;
              &lt;input name="login[username]" id="email" class="input-text" title="Email" data-validate="{required:true, 'validate-email':true}" aria-required="true" type="email"&gt;
          &lt;/div&gt;
          &lt;div class="header-login"&gt;
              &lt;span&gt;Password&lt;/span&gt;
              &lt;input name="login[password]" id="pass" class="input-text" title="Password" data-validate="{required:true}" aria-required="true" type="password"&gt;
  
          &lt;/div&gt;
          &lt;div class="header-login1"&gt;
              &lt;button type="submit" class="action login primary" name="send" id="send2"&gt;&lt;span&gt;Login&lt;/span&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;a href="&lt;?php echo $this-&gt;getUrl('customer/account/forgotpassword');?&gt;" class="f-right" style="padding: 3px 5px;"&gt;Reset Your Password?&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;?php } ?&gt; 
  </code></pre>
  
  <p>Plugin Code - </p>
  
  <pre><code>&lt;?php
  namespace Vendor\Module\Plugin;
  class LoginPostPlugin
  {
  
      /**
       * Change redirect after login to home instead of dashboard.
       *
       * @param \Magento\Customer\Controller\Account\LoginPost $subject
       * @param \Magento\Framework\Controller\Result\Redirect $result
       */
      public function afterExecute(
          \Magento\Customer\Controller\Account\LoginPost $subject,
          $result)
      {
          $result-&gt;setPath('/'); // Change this to what you want
          return $result;
      }
  
  }
  </code></pre>
  
  <p>I want to redirect the customer to $currenturl. Link tutorial can be able to redirect to the home page. Please suggest what needs to be done to achieve to redirect the customer to the current page. </p>