Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routes in Codeigniter - 404 Page Not Found

Can someone tell me, where the issue 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 is my routes.php

$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 404 Page Not Found error

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

I don't have anything in routes related to support and every other method is working Is there anything that i'm missing in routes ??

Thanks for the help.

like image 446
Satish Ravipati Avatar asked Aug 10 '13 21:08

Satish Ravipati


People also ask

How do I fix Error 404 Not Found?

404 error messages may occur when internet users come from external links from other sites that redirect them to deleted web pages. To solve this issue, restore the site backup. Note that this method only works if certain website pages are broken or show a 404 error.

How do you fix not found the requested URL was not found on this server?

You may receive a 404 error because the page did not load properly. Refreshing or reloading the webpage may fix the issue. You may refresh the page by clicking the refresh button at the top of your web browser or pressing the F5 button on your keyboard.


1 Answers

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

If so, change the following in config.php:

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

Back to the topic, you could achieve that by using the single-line route below within 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.

like image 142
Hashem Qolami Avatar answered Oct 08 '22 00:10

Hashem Qolami