我正在使用 Ubuntu 13 并为本地 codeigniter 站点进行以下设置。
Apache/2.4.6 (Ubuntu)
5.5.3-1ubuntu2.2
'CI_VERSION', '2.1.2'
如果没有,URL 将不再有效index.php
。他们曾经工作过,但升级后Ubuntu 12.x
to 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
没有任何作用
in the .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,但这些项目已经存在。很困惑可能是什么问题。
解决方案:
事实证明这根本不是 codeigniter 的问题。这是一个 apache 问题,但与重写规则无关。
在我的 apache2.conf 中,我必须更改 /var/www/ 的块
要求所有授予似乎已经成功了。
目录索引index.phpindex.html
期权指数 FollowSymLinks
允许覆盖全部
要求全部授予
为了更好地衡量,我也在这里进行了更改:
选项跟随符号链接
允许覆盖全部
要求全部授予
在 askubuntu 上找到https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working