2013-02-22 137 views
0

我该如何删除index.php以便使URL欺骗CI可以被利用?当我删除'index.php'时,它将通过404错误或403错误,即使控制器上存在必需的类。CodeIgniter中的htaccess问题

这里是目前我的根的.htaccess:在config.php文件

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

其他CI规格:

$config['index_page'] = ''; 

$config['uri_protocol'] = 'AUTO'; 

的rewrite_module启用。

在httpd.conf中:

<Directory /> 
Options FollowSymLinks 
AllowOverride None 
Order Allow,Deny 
Allow from all 
</Directory> 

编辑:要清楚,我可以访问我的应用程序(http://localhost/projectfolder)的 '主页'。但是,当我访问特定的控制器(http://localhost/projectfolder/admin)时,它不起作用。但是当主机和控制器之间有一个index.php时(http://localhost/projectfolder/index.php/admin),它就可以工作。我正在寻求解决之间的'index.php'。

+1

你不能简单地删除index.php作为引导CodeIgniter应用程序/框架。随意将它移动到另一个目录,并指出你的文件根目录。 – 2013-02-22 16:40:25

+0

这将帮助你: http://stackoverflow.com/questions/15017448/how-can-remove-index-php-from-url/15017916#15017916 – 2013-02-23 05:45:07

回答

0

请确保mod_rewrite已启用。另外,请尝试httpd.conf中这样

<Directory /youdirectory path> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Order allow,deny 
      allow from all 
</Directory> 

也请检查CodeIgniter的URL设置here

+0

正如我刚才提到的,rewrite_module启用( mod_rewrite的)。我已经尝试过,但无济于事。 – 2013-02-23 04:54:47

0

扩展在永联的评论:

你没有物理删除index.php文件。你会得到一个403,因为目录列表被拒绝(并且index.php不存在),并且控制器/方法上的一个404会因为它们不存在而导致url。

把CodeIgniter index.php放回它所属的地方,你应该没问题。此行:

$config['index_page'] = ''; 

是“去除”index.php的重要部分。有了这个空白,CodeIgniter的url/uri helper函数将不会在网址中放入index.php

有关更多信息,请参阅my answer正确的base_url

+0

我没有删除任何index.php。 CI的引导程序仍然是项目的根源。 – 2013-02-23 04:50:18

+0

另外,$ config ['index_page']为空。 – 2013-02-23 04:59:21

+0

那么你可以尝试评论'RewriteCond $ 1!^(index \ .php | images | robots \ .txt)吗? – Brendan 2013-02-25 14:27:08

0

如果您使用本地主机,那么您的$ _SERVER ['DOCUMENT_ROOT']将取决于您的wamp或xampp文件夹。它不会包含您的项目文件夹名称。

所以如果你的项目文件夹名称是假设“测试”,那么你必须写下你的htaccess如下。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /test/index.php/$1 [L] 

您必须在最后一行添加“test /”,您不需要在URL中添加index.php。 我希望这会起作用。

0

几次阅读你的问题后,它终于有道理了。我相信你需要添加一个像下面这样的RewriteBase:

RewriteEngine on 
RewriteBase /projectfolder/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L]