【问题标题】:Removing index.php using codeigniter 2使用 codeigniter 2 删除 index.php
【发布时间】:2016-11-08 09:08:40
【问题描述】:

我想从 url 项目文件夹中删除“index.php”链接,但它返回错误 404 Page Not Found。

我的默认网址是:
http://localhost/training/belajaradmin/
它工作得很好。这个网址也是如此
http://localhost/training/belajaradmin/index.php/login

但是,当我在删除 index.php:
http://localhost/training/belajaradmin/login
时放置此 URL 时,代码不起作用。

我使用codeigniter 2.2.6。下面的代码是文件的名称和我所做的更改。

.htaccess 在根目录

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

“应用程序”文件夹中的 config.php

$config['base_url'] = 'http://localhost/training/belajaradmin/';
$config['index_page'] = '';

'application'文件夹中的autoload.php

$autoload['helper'] = array('url');

'application'文件夹中的routes.php

$route['default_controller'] = "login";

【问题讨论】:

  • RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
  • 我这样做了,但它不起作用

标签: php codeigniter codeigniter-2


【解决方案1】:

在 .htaccess 中 RewriteEngine on 之后添加以下行

RewriteBase    /training/belajaradmin/

编辑配置如下:

$config['base_url'] = ''; 
$config['index_page'] = '';

【讨论】:

  • 谢谢!它现在确实像魅力一样工作。我只是编辑 .htaccess 文件,然后它就可以按我的意愿工作了。至于 config.php,我没有按照您的建议进行更改,因为我的 css 看起来不同。
  • 快乐编码 :)
【解决方案2】:

激活 mod_rewrite 模块

sudo a2enmod rewrite

重启apache

sudo service apache2 restart

【讨论】:

猜你喜欢
  • 2013-04-19
  • 1970-01-01
  • 2011-07-09
  • 1970-01-01
  • 2016-07-26
  • 2012-10-30
  • 2019-04-06
  • 2019-08-03
  • 2017-04-04
相关资源
最近更新 更多