CodeIgniter Forums
Codeigniter 4 Redirect not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Codeigniter 4 Redirect not working (/thread-75758.html)



Codeigniter 4 Redirect not working - RuudTableaux - 03-13-2020

Codeigniter 4
Im visiting my /admin route. During the execution im checking stuff so im inside a Library updating my routes file (for caching purposes) After this i want to redirect to the same route (/admin) But this doesnt work.

Ive tried:

```
$theurl = current_url(); //outputs http://mylocalurl.local/admin
redirect($theurl);


$theurl = current_url(); //outputs http://mylocalurl.local/admin
redirect()->to($theurl);

redirect("/admin");

redirect()->to("/admin");

redirect("admin");


redirect()->to("admin");
```


Ive added this in my Config/Routes.php file:
```
$routes->add('admin', 'Company\Admin\Controllers\Admin::index');
```

Any ideas?


RE: Codeigniter 4 Redirect not working - MGatner - 03-13-2020

Since you aren’t using a named route you should definitely use the “to()” method. This method expects a full URL for input, so partials will often work but you’re safer to do something like:
return redirect()->to(site_url(‘admin’));