CodeIgniter删除index.php不工作


CodeIgniter removing index.php not working

我正在使用Ubuntu 13和以下设置作为本地codeigniter站点。

Apache/2.4.6 (Ubuntu)
5.5.3-1ubuntu2.2 
'CI_VERSION', '2.1.2'

和url不再工作没有index.php。它们曾经工作,但在过去的一年中从Ubuntu 12.x升级到13.x和一些apache更新后,localhost站点不再正常工作。

如果我转到localhost/index.php/controllername/,它可以工作,但如果我转到localhost/controllername/,它不能。

mod_rewrite是enabled.

CodeIgniter config has:

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; // tried all available options here and 

毫无效果

.conf文件中的域,我有这个:

<Directory />
  Options -Multiviews +FollowSymLinks
  AllowOverride All
</Directory>

和这里的.htaccess文件注释行是我尝试的,没有工作。

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
#  RewriteCond $1 !^(index'.php|robots'.txt)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
#  RewriteRule .* index.php/$0 [PT,L]
#    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

我已经在谷歌上搜索并阅读了我能找到的所有内容,并尝试了我能找到的所有内容,包括Stack Overflow上的一些帖子,包括"可能已经有答案的问题"中的那些。但似乎什么都不起作用。但就像我说的,这在过去是有效的,但只有在对操作系统和Apache进行多次更新后,我才第一次注意到它停止工作。

我将在未来的项目中远离CodeIgniter,但这些项目已经存在。不知道是什么问题。

解决方案:

证明这根本不是代码编写器问题。这是apache的问题,但与重写规则无关。在我的apache2.conf中,我必须更改/var/www/

Require all granting似乎成功了。

目录索引index.php index.htmlOptions索引FollowSymLinksAllowOverride所有要求全部同意

为了更好地衡量,我在这里也做了改变:FollowSymLinks选项AllowOverride所有要求全部同意

在askubuntu上找到https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working

将以下代码复制到根文件夹.htaccess

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

在CodeIgniter中删除index.php对我来说很好

似乎CodeIgniter没有默认的.htaccess,所以不清楚它来自哪里。但出于调试目的,我建议您执行以下操作。首先,这是你的.htaccess全部清理:

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

现在用这个替换你的index.php。它只是转储通过.htaccess传递的$_GET值,如下所示:

echo '<pre>';
print_r($_GET);
echo '</pre>';

现在在你的.htaccess中加载网站/应用程序/项目的索引页。输出应该像这样:

Array
(
    [/controllername/here/] => 
)

这似乎是正确的。但是,你会比我们更清楚。

这样做的目的是评估问题是否在Apache传递适当的$_GET值到您的CodeIgniter设置,这是一个问题。或者问题是否在CodeIgniter控制器逻辑本身。

我的直觉告诉我这个问题是在代码库中的CodeIgniter逻辑中,因为从Ubuntu 12.x升级到Ubuntu 13.x包括PHP的升级版本,从Ubuntu 12.x5.3版本升级到Ubuntu 13.x5.5版本。我正在使用许多在PHP 5.3PHP 5.4中工作的代码,但在PHP 5.5中有时会中断,因为该代码库中有重大变化,如果您不保持非折旧函数的顶部,将导致代码中断。div。

我会尝试这样做:

RewriteRule ^(?!index)(.*)$ index.php?/myvariable=$1 [L]

如果您知道脚本在localhost/controllername中期望controllername的GET变量,那么在规则中将myvariable替换为该变量名称。

将.htaccess文件放入项目文件夹,如下所示:

根/your_project/. htaccess

.htaccess:

RewriteEngine on 
RewriteBase /your-project-directory-name/ 
RewriteCond $1 !^(index.php|resources|robots.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA]