【问题标题】:Cannot remove index.php from codeigniter [duplicate]无法从 codeigniter 中删除 index.php [重复]
【发布时间】:2013-08-02 05:31:31
【问题描述】:

我已将$config['index_page'] 更改为

$config['index_page'] = ''

并将我的 .htaccess 文件内容更新为:

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

但如果不将 index.php 放入我的 url,我将无法访问控制器。 那么接下来我该怎么做呢?

【问题讨论】:

  • 您的服务器是在 Linux 还是 Windows 上运行?
  • @cuewizchris,我在 Windows 上运行
  • 您需要确保您的重写引擎正在运行,并且 - 也许 - 您的虚拟主机配置中有一行需要更改(从“AllowOverride None”到“AllowOverride All”)。我不确定这些步骤应该如何在 Windows 上完成。
  • .htaccess 在 Windows 服务器上默认没有打开。首先确保是这种情况。看看这个回复和关于配置它的文章:stackoverflow.com/questions/14148489/…

标签: php codeigniter .htaccess


【解决方案1】:

尝试使用以下 .htaccess,它对我来说很好。

# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php

# Rewrite engine
RewriteEngine On

# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

【讨论】:

    【解决方案2】:

    试试这个

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

    将此代码放入您的根文件夹 htaccess 文件中,并清除您的应用程序文件夹 htaccess 文件的内容。

    如果您遇到任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 2013-08-09
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 2018-10-16
      • 2023-03-25
      • 2016-04-21
      相关资源
      最近更新 更多