2014-06-23 112 views
2

我正在使用Ubuntu 13与本地codeigniter站点的以下设置。CodeIgniter删除index.php不工作

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

而且,如果没有index.php,网址将不再有效。他们曾经工作过,但在从Ubuntu 12.x升级到13.x并在过去一年中进行了一些apache更新之后,localhost网站不再适用。

如果我去localhost/index.php/controllername/它的作品,但如果我去本地主机/控制器名/它不。

mod_rewrite已启用。

CodeIgniter的配置有:

$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> 

我GOOGLE和读到的一切我能找到,并试图一切我能找到其中的几个职位在这里对堆栈溢出,包括的那些“问题,可能已经有你的答案。”不过似乎没有什么工作。但正如我所说,这在过去有效,但只有在多次更新操作系统和Apache后,我才第一次注意到它停止工作。

我将远离CodeIgniter与未来的项目,但这些项目已经存在。关于什么可能是问题,感到困惑。

SOLUTION:

原来,这是不是一个笨问题都没有。这是一个Apache的问题,但没有重写规则。 在我的apache2.conf我不得不改变/ var/www/

块要求所有授予似乎已经做了伎俩。

的DirectoryIndex index.php文件index.html的 选项指标的FollowSymLinks 的AllowOverride所有 要求所有授予

只是良好的措施,我在这里所做的变化,以及: 有FollowSymLinks 的AllowOverride所有 要求all granted

found on askubuntu https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working

+0

你确定'mod_rewrite'已启用吗?它不是默认值:'sudo a2enmod rewrite'。然后'sudo service apache2 restart'。 – JakeGould

+0

你是否设置了空白变量?在配置文件? $ config ['index_page'] ='index.php'; 应该是这样的$ config ['index_page'] =''; –

+0

阅读此也http://ellislab.com/forums/viewthread/155801/ –

回答

0

似乎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控制器逻辑本身内。

我的直觉告诉我,问题是在你的代码库的笨逻辑,因为从Ubuntu 12.x升级到Ubuntu 13.x包括PHP5.3版本Ubuntu 12.xUbuntu 13.x的升级版,以5.5版本。我使用的许多代码在PHP 5.3PHP 5.4中有效,但在PHP 5.5中有时会中断,因为该代码库中的主要更改会导致代码中断,因为如果您不保留非折旧功能&等。

0

我会尝试这样的:

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

如果你知道什么GET变量的脚本在localhost/controllername期待的controllername,然后在规则与变量名替换myvariable

1

复制下面的代码.htaccess在您的根文件夹

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

Options All -Indexes 

也能正常工作对我来说,笨的index.php删除。