CodeIgniter/Bonfire应用程序显示页面中的路由未找到


Routes in CodeIgniter/Bonfire application displays page not found

我有一个定义了路由的CodeIgniter/Bonfire应用程序
主URL工作正常,但子页面不会重定向
当我输入URL时:

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

我得到错误PAGE NOT FOUND,看起来它找不到base_url:

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

这是我在application/config/routes.php:中的路由文件

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

我的配置文件定义了我的base_url:

switch (ENVIRONMENT)
    {
        case 'development':
            $config['base_url'] = 'http://xtrack.local';
            break;
        default:
            exit('The application environment is not set correctly.');
    }

第1版:我找到了一种通过index.php页面访问我的新闻页面的方法:

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

index.php文件是必要的,因为它是应用程序的入口点,可以准备好所有组件,包括路由器。不过,您可以在apache主机上使用.htaccess文件隐式地将请求传递给该文件。来自手册:


默认情况下,index.php文件将包含在您的URL:中

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

通过使用.htaccess文件和一些简单的规则,您可以很容易地删除此文件。下面是这样一个文件的例子,使用"负"方法,除指定项目外,所有内容都被重定向:

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

在上面的例子中,除了index.php之外的任何HTTP请求,图像,robots.txt被视为对index.php的请求文件


因此,URL将变为example.com/news/article/my_article,或者在您的情况下,变为帖子开头的URL。