【问题标题】:Index.php remove from url is not working in CI 3从 url 中删除的 Index.php 在 CI 3 中不起作用
【发布时间】:2016-12-22 10:49:59
【问题描述】:

我已经尝试了很多从 url 中删除 index.php 。 它根本不工作。

在 config.php 中

$config['index_page'] = '';

$config['uri_protocol'] = 'REQUEST_URI';

然后将下面的代码放在我的项目根目录的 .htaccess 中。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

我试过了,它的投掷页面只没有发现错误。

有什么建议吗?? 谢谢

【问题讨论】:

  • .htaccess RewriteBase /cloud
  • @James Lalor,非常感谢你为我所做的工作。谢谢你还不够。 :) :)
  • @sradha 写了一个答案,请标记为已接受。

标签: php .htaccess codeigniter


【解决方案1】:

您的基础 URL 不是基础域名,因此请修改您的 .htaccess 文件并添加以下内容:

RewriteBase /cloud

这应该可以解决您的问题。

【讨论】:

    【解决方案2】:

    您需要更改config.php.htaccess 文件。

    application/config/config.php 的变化

    $config['index_page'] = ""; // And Remove index.php
    

    .htaccess 的变化

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    #RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    

    确保

    1. 您的.htaccess 必须在cloud 目录下。

    2. 必须在 Apache 中启用重写模块。

    【讨论】:

    • localhost/cloud/index.php/dashboard/index 它在本地主机中..我无法显示给你。我想删除 index.php 的链接应该是 . localhost/cloud/dashboard/index
    • @sradha 请签入application/config/routes.php default_controller 应该是$route['default_controller'] = 'dashboard';
    • 但是我的默认控制器是登录,第一个登录页面会出现所以我给了登录
    • @sradha 是否在 url 中没有 index.php 的情况下登录?
    • 是的,如果我给localhost/cloud 登录页面即将到来。正如我所提到的 $route['default_controller'] = 'Login';
    【解决方案3】:

    试试这个,
    .htaccess的变化

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    

    【讨论】:

      【解决方案4】:

      确保您的 RewriteEngine 在 apache conf 文件中打开,如果没有,请点击此链接

      How to enable mod_rewrite for Apache 2.2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-10
        • 1970-01-01
        • 2015-09-28
        • 2018-07-12
        • 2016-11-23
        • 2021-12-15
        • 1970-01-01
        • 2015-05-22
        相关资源
        最近更新 更多