【问题标题】:Codeigniter URI RoutingCodeigniter URI 路由
【发布时间】:2012-06-04 15:32:18
【问题描述】:

我已经查看了 codeigniter 用户指南,但我没有幸运地解决了我的问题。

我在本地主机上创建了一个网页。

当我去http://localhost/webpage/ 时,没关系。它将转到默认控制器。

我的默认控制器是Homepage,并且有名为indexguaranteeabout的方法

当我转到我的 routes.php 时,我添加了这个:

$route['guarantee'] = "homepage/guarantee";
$route['about_us'] = "homepage/about";

然后尝试访问它http://localhost/webpage/guaranteehttp://localhost/webpage/about_us 它显示错误404

但是当我这样做时$route['default_controller'] = "homepage/guarantee";会显示保证页面。

谁能帮我解决这个问题? 谢谢。

【问题讨论】:

  • 您在此文件夹中有.htaccess 文件吗?
  • 在应用程序文件夹中,有一个.htaccess。我没有碰它。这是我正在使用的 CodeIgniter 的新副本。
  • 没关系,我只是问你是否在根目录中添加了一个。你试过http://localhost/webpage/index.php/guarantee 吗?
  • 是的,它有效。谢谢,但是如何删除 index.php

标签: codeigniter codeigniter-routing


【解决方案1】:

您需要删除 index.php。在您的 application/config.php 文件中更改

$config['index_page'] = 'index.php';

$config['index_page'] = '';

然后将这个 .htaccess 文件放在你的根文件夹中(与 index.php 所在的文件夹相同:

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # Activate URL rewriting:
RewriteEngine on

# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(uploads|assets|js|css|images|img)


    # but rewrite everything else
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>  

【讨论】:

    【解决方案2】:

    在您的application/config/config.php 中,将$config['index_page'] 设置为空 $config['index_page'] = ''; 应该可以工作。

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 2014-12-06
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      相关资源
      最近更新 更多