【问题标题】:Unable to remove index.php in Codeigniter无法在 Codeigniter 中删除 index.php
【发布时间】:2016-04-21 14:56:25
【问题描述】:

我想删除 index.php 以直接访问我的控制器。但是,我不能直接去我的控制器。我必须使用 index.php。例如:我想去 http://example.com/my_controller/method 而不是 http://example.com/index.php/my_controller/method

顺便说一句,我使用的是我的测试服务器,而不是像 XAMPP 这样的本地服务器。我在我的服务器中启用了 apache mod rewrite。

我尝试了很多 htaccess 规则,条件,但我无法工作。请帮帮我!

这是我的 .htaccess 文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

我的 config.php:

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

我怎样才能直接去?

【问题讨论】:

  • 首先你使用的是什么版本的codeigniter以及什么localhost xampp、wamp等
  • 我使用我的服务器来测试它。
  • 如果您使用 wamp,请确保您已启用 apache mod rewrite。并使您的 htaccess 位于应用程序文件夹之外的主目录中。
  • @wolfgang1983 不,我不使用它,因为我使用的是我的测试服务器,而不是本地服务器。另外,我在我的服务器中启用了 apache mod rewrite,并尝试了主目录。

标签: php .htaccess codeigniter config


【解决方案1】:

在您的 .htaccess 文件中尝试此代码

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

【讨论】:

  • 更改.htaccess后是否重启了服务器
  • 是的,我做到了。如果我没有重新启动它,我无法通过使用 phpinfo() 在加载的模块中看到该模块
【解决方案2】:

如何验证 mod_rewrite 是否已实际启用。您可以按照此处的说明进行操作:How to check whether mod_rewrite is enable on server?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 2013-08-09
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2018-10-16
  • 2013-08-02
相关资源
最近更新 更多