Routes in Codeigniter - 404 Page not found

Can someone tell me where the problem is?

This is my controller

class Support extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('support_model'); $urlarray = array("index","delete"); if(!in_array($this->uri->segment(2),$urlarray)){ $this->viewticket($this->uri->segment(2)); } } public function viewticket($id){ if(!empty($id)){ $this->load->view('templates/logged_header'); $this->load->view('support/view'); $this->load->view('templates/footer'); } } } 

Here are my .php routes

 $route['default_controller'] = "welcome"; $route['benefits'] = 'welcome/benefits'; $route['faqs'] = 'welcome/faqs'; $route['distributors'] = 'welcome/distributors'; $route['contact'] = 'welcome/contact'; $route['purchase'] = 'welcome/purchase'; //login routes $route['login'] = 'login/index'; $route['logout'] = 'login/logout'; $route['404_override'] = ''; 

localhost/ciproj/support/hello-world gives me a 404 Page Not Found error

If I use exit; after $this->load->view('templates/footer'); , the page shows me a blank page.

I have nothing in the routes related to support, and every other method works. Is there something I miss in the routes?

Thanks for the help.

+4
source share
1 answer

Judging by the title, first of all check if PHP is running on your server using CGI/FastCGI or not (you can just check that phpinfo() ).

If so, change the following in config.php :

 $config['uri_protocol'] = "REQUEST_URI"; 

Back to the topic, you can achieve this using the single-line route below in your routes.php file:

 $route['support/(?!index)(?!delete)(:any)'] = "support/viewticket/$1"; 

And remove these lines from your __construct method:

 $urlarray = array("index","delete"); if(!in_array($this->uri->segment(2),$urlarray)){ $this->viewticket($this->uri->segment(2)); } 

Let me know how it works.

+5
source

Source: https://habr.com/ru/post/1496351/


All Articles