• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect and baseURL with subdir not working

#1
Just checking if I am doing something wrong.
Currently, https://github.com/codeigniter4/CodeIgni...ssues/2445 is the only thing that keeps me from adopting CI4 completely as I need to hack a system file to get it to work. I have downloaded the latest develop from github but still no go.

So, my question is - is it me doing something wrong?

I have baseURL = 'https://backend.tangixdev.se/client/'
I have updated public/.htaccess and changed the RewriteBase:
Code:
RewriteBase /client/

Routes are setup:
Code:
$routes->add('home', 'Home::index');
$routes->add('home/test', 'Home::test');
$routes->add('home/index', 'Home::index');


Now trying to do redirects from https://backend.tangixdev.se/client/home/test and it doesn't work:
Code:
return $this->response->redirect('/home/index'); // redirects to https://backend.tangixdev.se/home/index
Trying:
Code:
return $this->response->redirect('home/index'); // redirects to https://backend.tangixdev.se/client/home/home/index

The only thing that works for me is:
Code:
return $this->response->redirect(site_url('home/index'));

Is the last snippet the correct way to do a redirect? But this seems to override the routing logic?

According to the documentation we should do something like this:
Code:
return $this->response->redirect()->to('/home/index');

But this gives error: Too few arguments to function CodeIgniter\HTTP\Response::redirect(), 0 passed in

If anyone could point me in the right direction that would be much appreciated. As indicated in the issue reference, my only way forward is using site_url() or hack the framework file.
Too few arguments to function Code
Reply

#2
(01-13-2020, 11:57 PM)tgix Wrote: Just checking if I am doing something wrong.
Currently, https://github.com/codeigniter4/CodeIgni...ssues/2445 is the only thing that keeps me from adopting CI4 completely as I need to hack a system file to get it to work. I have downloaded the latest develop from github but still no go.

So, my question is - is it me doing something wrong?

I have baseURL = 'https://backend.tangixdev.se/client/'
I have updated public/.htaccess and changed the RewriteBase:
Code:
RewriteBase /client/

Routes are setup:
Code:
$routes->add('home', 'Home::index');
$routes->add('home/test', 'Home::test');
$routes->add('home/index', 'Home::index');


Now trying to do redirects from https://backend.tangixdev.se/client/home/test and it doesn't work:
Code:
return $this->response->redirect('/home/index'); // redirects to https://backend.tangixdev.se/home/index
Trying:
Code:
return $this->response->redirect('home/index'); // redirects to https://backend.tangixdev.se/client/home/home/index

The only thing that works for me is:
Code:
return $this->response->redirect(site_url('home/index'));

Is the last snippet the correct way to do a redirect? But this seems to override the routing logic?

According to the documentation we should do something like this:
Code:
return $this->response->redirect()->to('/home/index');

But this gives error: Too few arguments to function CodeIgniter\HTTP\Response::redirect(), 0 passed in

If anyone could point me in the right direction that would be much appreciated. As indicated in the issue reference, my only way forward is using site_url() or hack the framework file.
Too few arguments to function Code

Yep definitely it is the bug. So far use it with base_url() and you should be fine. I do the same a when the problem will be fixed, you can change it, anyway that redirect function does as you would do it manually with base_url().
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.