2

I need to redirect '/home' URL to '/' in Codeigniter 4.

The code below does it perfectly, but I wonder if there is a better way to do this inside the Routes.php file.

$routes->get('/', 'Pages::view/home');
$routes->get('/home', function()
    {
        header('Location: '.'/');
    }
);

ANSWER

$routes->get('/', 'Pages::view/home');
$routes->addRedirect('/home', '/');
FedeKrum
  • 435
  • 1
  • 6
  • 15
  • Did you try this ? https://codeigniter.com/user_guide/incoming/routing.html#redirecting-routes I have never used it but seems like a fair option – ViLar Apr 22 '21 at 09:10
  • @ViLar, how would that code be for my example? I read that but was not able to make it work. – FedeKrum Apr 22 '21 at 09:52

0 Answers0