【问题标题】:Codeigniter 3.1.6 - How to remove index.php from urlCodeigniter 3.1.6 - 如何从 url 中删除 index.php
【发布时间】:2018-03-18 10:42:12
【问题描述】:

我正在开发 codeigniter 3.1.6。

我添加了 .htaccess 文件。 我还将base_url 路径更改为我的项目路径,从index_page 中删除了index.php,并将url_protocol 更改为REQUEST_URI

尽管如此,当我将 url 重定向到任何控制器方法时,它会抛出错误,如“The page you requested was not found”。

我还搜索并应用了不同的 .htaccess,但它不起作用。 如果我在 base_url 末尾添加/index.php,那么它可以工作,但它是错误的。它应该在没有 index.php 的情况下工作。只有 3.1.6 给出了这个问题。

注意:codeigniter-3.1.4 工作正常,只有这个版本有问题

【问题讨论】:

标签: php .htaccess codeigniter codeigniter-3


【解决方案1】:

将文件夹名称 CodeIgniter-3.1.6 更改为 ci

将您的 base_url 设置为

$config['base_url'] = 'http://localhost/ci/

使用这个.htaccess

RewriteEngine On
RewriteBase /ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

【讨论】:

  • 很棒的兄弟,它有效。但这一切都在发生吗?死于失踪RewriteBase /ci?对于其他版本,我还没有使用这样的线,它们仍然工作正常吗?怎么样?
  • 太棒了。要编辑的 .htaccess 文件应该是根文件夹中的文件。不是应用程序文件夹中的那个
【解决方案2】:

在 .htaccess 中使用这个脚本

<IfModule mod_rewrite.c>
   RewriteEngine On
   # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)

  RewriteRule ^(.*)$ index.php?/$1 [L]
  # If your root folder is at /mypage/test1/
  RewriteRule ^(.*?)$ /mypage/test1/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.
 # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
 </IfModule>

config.php 中删除index.php $config['index_page'] = '';

【讨论】:

  • 不工作@Sunday
【解决方案3】:

1) 编辑config.php

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

 $config['index_page'] = '’;

2) 创建/编辑 .htaccess 文件

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

【讨论】:

  • 不工作兄弟。已经这样做了。只有这个版本给出了问题。我是第一次使用这个版本
【解决方案4】:

1:在根目录而不是另一个项目文件夹目录中创建.htaccess文件。

2:编写或复制此代码并粘贴

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

我希望这会正常工作。 进入配置文件并进行更改 $config['url_protocol']='auto';

【讨论】:

    【解决方案5】:

    附加提示:确保根文件夹中的 .htacces 不在 >application 文件夹中

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 2015-10-24
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2012-09-21
      • 2011-10-12
      相关资源
      最近更新 更多