0

in our magento application we have somehow a 302 redirect from /customer/account into /connexion. I would like to change it into a 301 one. No idea how to process this.

This seems to be handled in a specific plugin

di.xml

<type name="Magento\Framework\Url">
    <plugin name="custom_login_url" type="Cpy\MyModule\Plugin\Framework\Url" disabled="false" />
</type>

Url.php

<?php

namespace Cpy\MyModule\Plugin\Framework;

class Url
{
    public function aroundGetUrl($subject, $callable, $routePath = null, $routeParams = null)
    {
        if($routePath == 'customer/account/login') {
            $routePath = 'connexion';
            $routeParams = null;
        }
        return $callable($routePath, $routeParams);
    }
}

Any ideas ?

EDIT :

<?php

namespace Cpy\MyModule\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        $this->_forward('login', 'account', 'customer');
    }
}
0

Magento provides to do custom redirection from admin. You just need to add it url rewrites.

Please go to admin panel > Marekting > Url Rewrites

According to your requirement please add like as per screenshot- https://prnt.sc/13i53zg

Please save it and flush cache. After that please check in front end.

Or use below code in .htaccess

Redirect 301 /customer/account/login http://www.yoursite.com/connexion/
3
  • I should have mentionned that we want to do that programmaticaly...for some reasons, the client only want product rewrite on the admin section...
    – Claims
    May 28 '21 at 9:03
  • 1
    The plugin you used is definitely not redirect customer to new page. It will only generate a link of "connexion" page when you ask for url of login page. There might some where else logic for redirection. If you can share that code we can guide you correctly or if you do not want to do it from admin then you can do it from htacess as well. I updated the answer
    – ZealousWeb
    May 28 '21 at 10:55
  • Thanks for your help, following your advice i've been digging a little bit more and i found this controller (i added it in the question) it might be the place where the real redirection is made i guess. So that's probably the part i need to change to got that 301 redirection.
    – Claims
    May 28 '21 at 12:11

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.