从子目录中的CI中删除index.php

从子目录中的CI中删除index.php,php,.htaccess,codeigniter,mod-rewrite,Php,.htaccess,Codeigniter,Mod Rewrite,我在stackoverflow上看到了很多类似我的问题,但所有的解决方案都不适合我 我有example.com和codeigniter应用程序example.com/codeigniter这样的域 我在主目录中没有任何.htaccess,但我想从我的codeigniter应用程序中删除index.php config.php: $config['base_url'] = 'http://example.com/codeigniter'; $config['index_page'] = ''; $

我在stackoverflow上看到了很多类似我的问题,但所有的解决方案都不适合我

我有example.com和codeigniter应用程序example.com/codeigniter这样的域

我在主目录中没有任何.htaccess,但我想从我的codeigniter应用程序中删除index.php

config.php

$config['base_url'] = 'http://example.com/codeigniter';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我试过:

RewriteEngine on
RewriteBase codeigniter
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
但我有一个错误:

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求

请与服务器管理员联系,postmaster@example.com并告知他们错误发生的时间,以及您可能采取的任何可能导致错误的措施

有关此错误的详细信息,请参阅服务器错误日志

下一个解决方案也不起作用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /codeigniter/index.php?/$1 [L]
因为当我尝试调用我的控制器(如www.example/codeigniter/user/login)时,我出现了错误:

找不到

在此服务器上找不到请求的URL/codeigniter/user/login


在config.php中保留默认设置

请尝试访问代码:

在我的Ubuntu服务器中,以下内容对我很有用:

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
还要确保在服务器上启用了“重写”模块。 您可以使用以下代码进行检查:

print_r(apache_get_modules());

检查这些差异:

APPPATH.config/config.php'
中:

$config['base_url'] = 'http://example.com/codeigniter/';
.htaccess
中:

RewriteEngine on
RewriteBase /codeigniter/
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

我的答案中的差异主要是使用斜杠。要按常规方式运行,CI需要
base\u url()
以斜杠结尾。Apache
.htaccess
文件需要被告知从根开始的位置,该位置用起始斜杠表示。结束斜杠是告诉Apache任何附录都应该以无斜杠开头。这就像根目录中的“重写基”是用斜杠设置的,或者更好的说法是以斜杠结束。如果注释中出现更多错误,请尝试此操作,因为不同的服务器可以对
.htaccess
代码进行不同的解释。

不同的托管提供商可以有不同的Apache规则,这可能会影响您编写
.htaccess
文件所需的方式。我使用GoDaddy作为客户机,花了2个小时才找到一个有效的
.htaccess
。你使用什么主机提供商?试试RewriteBase/codeigniter
RewriteCond$1^(index\.php | assets | robots\.txt)
应该是
RewriteCond${REQUEST_URI}^(index\.php | assets | robots\.txt)
@CharlotteDunois它没有帮助,现在当我转到example.com/codeigniter时,我有example.com的内容。