CI4 Filter Redirection Problem |
Hi.
I'm having problems implementing a site-wide Filter redirection for maintenance. As you can see, I've tried to brute-force it using the infinite monkey theorem, but even this hasn't helped. This is what I have: - in app\Filters\MaintenanceFilter.php: <?php namespace App\Filters; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\Filters\FilterInterface; /* Down for maintenance filter */ class MaintenanceFilter implements FilterInterface { public function before(RequestInterface $request) { return redirect()->to(base_url().'Maintenance'); // doesn't work: * Firefox has detected that the server is redirecting the request for this address in a way that will never complete //return redirect()->to(base_url().'Maintenance/index'); // doesn't work: * //redirect()->to(base_url().'Maintenance/index'); // doesn't work - a completely blank page html/body only is presented, no error shown //redirect()->to(base_url().'Maintenance'); // doesn't work - a completely blank page html/body only is presented, no error shown //return redirect()->to('/Maintenance'); // doesn't work: * //redirect()->to('/Maintenance/index'); // doesn't work - a completely blank page html/body only is presented, no error shown - Status 200 (OK), but completely blank response //return redirect()->to('Maintenance'); // doesn't work: * //redirect()->to('Maintenance'); // doesn't work - a completely blank page html/body only is presented, no error shown - Status 200 (OK), but completely blank response //return redirect(base_url('Maintenance', 'refresh')); // doesn't work - throws HTTPException //redirect(base_url('Maintenance', 'refresh')); // doesn't work - throws HTTPException //return redirect(base_url('Maintenance', 'location')); // doesn't work - throws HTTPException //redirect(base_url('Maintenance', 'location')); // doesn't work - throws HTTPException //return redirect(base_url('Maintenance', 'location')); // doesn't work - HTTPException thrown //redirect(base_url('Maintenance', 'location')); // doesn't work - HTTPException thrown //return redirect(site_url('/Maintenance')); // doesn't work - goes to //localhost (not controller). 500 Internal Server Error thrown (seems to getting confused opening a css file first?) //redirect(site_url('/Maintenance')); // doesn't work - 500 Internal Server Error thrown (seems to getting confused opening a css file first?) //$url = base_url().'Maintenance'; //header("HTTP/1.1 301 Moved Permanently"); //header("HTTP/1.1 307 Temporary Redirect"); //header("Location: $url"); exit; // for testing when return is not used above } - in app\Config\Filters.php: <?php namespace Config; use CodeIgniter\Config\BaseConfig; class Filters extends BaseConfig { public $aliases = [ 'maintenance' => \App\Filters\MaintenanceFilter::class, ]; public $globals = [ 'before' => [ 'maintenance', // redirect all traffic to the "down for maintenance" page ], 'after' => [ 'toolbar', ], ]; public $methods = []; public $filters = []; } - in app\Controllers\Maintenance.php a controller that simply pulls up a very basic maintenance_view.php pager stored in app\Views (that will open without a problem if I type //localhost/Maintenance into my browser. This is the response I get in Firefox: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. And this, repeated about 20 times per attempt : GET http://localhost/Maintenance [HTTP/1.1 307 Temporary Redirect 50ms] Request URL: http://localhost/Maintenance Request method: GET Remote address: [::1]:80 Status code: 307 Temporary Redirect Version: HTTP/1.1 Is it just me? Though, I have see this: https://github.com/codeigniter4/CodeIgni...ssues/2383 and several related posts of people experiencing similar difficulties (going back to 2018 and before). I've tried the suggested work-around (including editing CodeIgniter4/system/HTTP/Response.php line 722), but none of it makes any difference (even though my installation of Firefox seemed to think the HTTP/1.1 header was there without this mod ?!). Any suggestions would be appreciated, thanks.
That message from Firefox is because there is an infinite redirect loop. You need an exception for the maintenance page in your filter, or don’t apply the filter to the maintenance page.
Also when posting please use code tags.
[ CODE] your_code [ /CODE] Remove the spaces or use the forums Reply to this Topic button which gives you a full editor. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |