【问题标题】:How to remove index.php from URLs in Kohana 3.1如何从 Kohana 3.1 中的 URL 中删除 index.php
【发布时间】:2011-08-06 20:54:59
【问题描述】:

目前,使用 Kohana 3.1,我可以使用以下方式访问我的控制器:

http://localhost/kohana/index.php/admin

但是,我想在中间没有“index.php”的情况下访问它们,如下所示:

http://localhost/kohana/admin

我该怎么做?我是否需要更改我的 .htaccess 文件或某些配置选项?

我正在使用 Kohana 提供的 .htaccess:

# 开启 URL 重写
重写引擎开启

# 安装目录
RewriteBase /

# 保护隐藏文件不被查看

    订单拒绝,允许
    拒绝所有人


# 保护应用程序和系统文件不被查看
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# 允许直接显示任何存在的文件或目录
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# 将所有其他 URL 重写为 index.php/URL
RewriteRule .* index.php/$0 [PT]

【问题讨论】:

    标签: kohana url-routing


    【解决方案1】:

    将 RewriteBase 指令更改为应用程序所在的位置。你会是:

    # Installation directory
    RewriteBase /kohana/
    

    还要确保您的引导程序中有正确的base_url

    【讨论】:

    • 完美! localhost 上的任何人都应该注意,base_url 或 htaccess 中不需要“localhost”。 (对我来说 kohana 3.2)
    【解决方案2】:

    但是,如果您使用Rewritebase /kohana/,您仍然会在网址中获得index.php。 我正在使用 Kohana 3,所以我转到 bootstrap.php 并更改此:

    Kohana::init(array(
        'base_url'   => '/',
        'index_file' => '',
    ));
    

    【讨论】:

      【解决方案3】:

      您似乎错过了 kohaha 文件夹。 它应该是这样的: Kohana::init(数组( 'base_url' => '/kohana/', 'index_file' => '', ));

      【讨论】:

        【解决方案4】:

        在一些网站上我看到了 .htaccess 建议:

        # Rewrite all other URLs to index.php/URL
        RewriteRule .* index.php?kohana_uri=$0 [PT,L,QSA]
        

        【讨论】:

          【解决方案5】:

          通过添加以下代码打开 URL 重写:

          在 .htaccess 中:

          RewriteEngine On
          # Installation directory
          RewriteBase /
          

          在引导中:

          Kohana::init(array( 'base_url' => '', 'index_file' => '' ));
          

          【讨论】:

            【解决方案6】:

            你需要在 bootstrap.php 中使用'index_file' => FALSE

            来源:http://kohanaframework.org/3.0/guide/kohana/tutorials/clean-urls

            【讨论】:

              猜你喜欢
              • 2011-07-06
              • 1970-01-01
              • 2012-05-15
              • 1970-01-01
              • 1970-01-01
              • 2013-05-15
              相关资源
              最近更新 更多