CodeIgniter Forums
redirect question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: redirect question (/showthread.php?tid=80271)



redirect question - paulkd - 10-11-2021

Hi,

Can someone tell me why this is redirecting to localhost rather than the domain it is being executed on Huh

Code:
return redirect()->to('/admin/login');



RE: redirect question - paliz - 10-11-2021

its not work in  construct 
it should  use filter 
PHP Code:
<?php namespace Myth\Auth\Filters;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;
use 
Config\App;

class 
LoginFilter implements FilterInterface
{
 
/**
 * Verifies that a user is logged in, or redirects to login.
 *
 * @param RequestInterface $request
 * @param array|null $params
 *
 * @return mixed
 */
 
public function before(RequestInterface $request$params null)
 {

 
$authenticate service('authentication');
 if (! 
$authenticate->check())
 {
 
session()->set('redirect_url'current_url());
 return 
redirect('login');
 }
 }

 
/**
 * @param RequestInterface  $request
 * @param ResponseInterface $response
 * @param array|null $arguments
 *
 * @return void
 */
 
public function after(RequestInterface $requestResponseInterface $response$arguments null)
 {
 }

but if you use in method
function  index(){
return  redirect()->to('login')
}


RE: redirect question - includebeer - 10-12-2021

(10-11-2021, 03:13 AM)paulkd Wrote: Hi,

Can someone tell me why this is redirecting to localhost rather than the domain it is being executed on Huh

Code:
return redirect()->to('/admin/login');

You sure you don’t have “localhost” in app.baseURL in your .env file?


SOLVED: redirect question - paulkd - 10-12-2021

(10-12-2021, 04:00 PM)includebeer Wrote:
(10-11-2021, 03:13 AM)paulkd Wrote: Hi,

Can someone tell me why this is redirecting to localhost rather than the domain it is being executed on Huh

Code:
return redirect()->to('/admin/login');

You sure you don’t have “localhost” in app.baseURL in your .env file?

Bingo!  Big Grin

The setting was actually commented out. Uncommenting and changing to the correct domain resolved the issue.

Thanks!