【发布时间】:2014-08-12 23:34:50
【问题描述】:
我正在为本地 codeigniter 站点使用具有以下设置的 Ubuntu 13。
Apache/2.4.6 (Ubuntu)
5.5.3-1ubuntu2.2
'CI_VERSION', '2.1.2'
如果没有index.php,URL 将不再有效。它们以前可以工作,但在从 Ubuntu 12.x 升级到 13.x 并在过去一年中进行了几次 apache 更新后,localhost 网站不再正常工作。
如果我去 localhost/index.php/controllername/ 它可以工作,但如果我去 localhost/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 上搜索并阅读了我能找到的所有内容,并尝试了我能找到的所有内容,包括 Stack Overflow 上的几篇帖子,包括“可能已经有你答案的问题”中的帖子。似乎仍然没有任何效果。但就像我说的,这在过去有效,但只有在多次更新操作系统和 Apache 之后,我才第一次注意到它停止工作。
我将在未来的项目中远离 CodeIgniter,但这些项目已经存在。对可能是什么问题感到困惑。
解决方案:
结果证明这根本不是代码点火器问题。这是一个 apache 问题,但与重写规则无关。 在我的 apache2.conf 中,我不得不更改 /var/www/ 的块
要求所有授予似乎已经成功了。
DirectoryIndex index.php index.html 选项索引 FollowSymLinks 允许覆盖所有 要求所有授予
为了更好的衡量,我也在这里进行了更改: 选项 FollowSymLinks 允许覆盖所有 要求所有授予
在 askubuntu 上找到 https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working
【问题讨论】:
-
您确定
mod_rewrite已启用吗?它不是默认的:sudo a2enmod rewrite。然后sudo service apache2 restart. -
您是否将变量设置为空白?在配置文件中? $config['index_page'] = 'index.php';应该是这样 $config['index_page'] = '';
-
看看这是一个重复的问题stackoverflow.com/questions/20814773/…
-
如前所述,我看到了很多关于 SO 的问题/答案,但没有一个对我的情况有所帮助。该问题中的重写规则正是我所拥有但不起作用的。事实证明,这根本不是 codeigniter 的问题,而是 apache 配置的问题。我必须在
下的 apache2.conf 中进行一些更改
标签: php apache .htaccess codeigniter mod-rewrite