Search code examples
phpcodeigniterroutesbonfire

Routes in CodeIgniter/Bonfire application displays page not found


I have a CodeIgniter/Bonfire application with routes defined.
The main URL works fine but the subpages are not redirected.
When I enter the URL:

http://xtrack.local/news/1393/litany-look

I got error PAGE NOT FOUND and looks like it cannot find the base_url:

Not Found
The requested URL /news/1393/litany-look was not found on this server.

Here is my routes file in application/config/routes.php :

$route['news/(:any)']                   = 'home/news/$1';

And my config file define my base_url :

switch (ENVIRONMENT)
    {
        case 'development':
            $config['base_url'] = 'http://xtrack.local';
            break;

        default:
            exit('The application environment is not set correctly.');
    }

EDIT1 : I found a way to access my news page through the index.php page:

http://xtrack.local/index.php/news/1393/litany-look

Solution

  • The index.php file is necessary because this is the entry point of the application that gets all components ready, including the router. You can use an .htaccess file on apache hosts to pass the request to this file implicitly though. From the manual:


    By default, the index.php file will be included in your URLs:

    example.com/index.php/news/article/my_article

    You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

    RewriteEngine on 
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.


    So then the URL would become example.com/news/article/my_article, or in your case the one at the start of your post.