【问题标题】:Routes in CodeIgniter/Bonfire application displays page not foundCodeIgniter/Bonfire 应用程序中的路由显示找不到页面
【发布时间】:2014-10-02 19:36:38
【问题描述】:

我有一个定义了路由的 CodeIgniter/Bonfire 应用程序。
主 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

【问题讨论】:

    标签: php codeigniter routes bonfire


    【解决方案1】:

    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,或者在您的情况下是您帖子开头的那个。

    【讨论】:

    • 太好了,你让我找到了答案:事实上,主要问题是我的虚拟主机路径不是通过 MAMP htdocs 文件夹定义的,而是通过非 Apache 路径定义的,所以我的 htaccess 不起作用一点也不。谢谢!
    猜你喜欢
    • 2013-08-12
    • 2020-10-21
    • 2019-01-09
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多