Welcome Guest, Not a member yet? Register   Sign In
CI4 Filter Redirection Problem
#1
Exclamation 

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.

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
CI4 Filter Redirection Problem - by Gary - 12-18-2019, 05:08 AM
RE: CI4 Filter Redirection Problem - by MGatner - 12-20-2019, 06:41 AM
RE: CI4 Filter Redirection Problem - by Gary - 12-23-2019, 07:06 AM
RE: CI4 Filter Redirection Problem - by InsiteFX - 12-23-2019, 08:58 AM
RE: CI4 Filter Redirection Problem - by Gary - 01-16-2020, 06:29 AM
RE: CI4 Filter Redirection Problem - by malsmary - 06-23-2020, 10:51 AM
RE: CI4 Filter Redirection Problem - by krislec - 01-02-2021, 10:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB