嗨,我目前正在做一个使用codeigniter的项目,我在linux (ubuntu 14.04)上的安装有问题,这个项目是在Windows机器上安装的,现在正在转移到linux机器上。
问题是,当我去到网站的默认页面,这是http://localhost/它去我的索引(这是正确的工作),但当我去到我的控制器的其他功能,它总是给出404 NOT FOUND。
(404 NOT FOUND) The requested URL /lin was not found on this server.
下面是代码示例
class Lin extends CI_Controller {
public function index() {
$data['main_content'] = 'login_form';
$this->load->view('includes/template', $data);
}
public function validate_credentials() {
var_dump("TEST");
exit;
}
如果我去http://localhost/lin/validate_credentials它显示测试转储和退出,但它给出404错误。
你试过了吗
http://localhost/index.php/lin/validate_credentials对不起,我不太确定哪个是先写的,我会改正的。
但如果它仍然不起作用。你的。htaccess
可能有问题创建一个名为'。Htaccess '在你的根目录中,是的,开头有一个点,里面是这段代码。当我使用这个,我生成干净的url没有index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /PUT YOUR ROOT FOLDER NAME HERE , DON'T REMOVE THE SLASH
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$l [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index'.php|images|robots'.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 / index.php
</IfModule>
我很抱歉,如果我不能解释这一行一行,但我总是把它放在codeigniter和工作完美,只是改变RewriteBase,你可以在互联网上搜索或在这里stackoverflow它的意思。
问题是由于您的机器上没有启用mod_rewrite。试试这个:
1. Enable mod_rewrite by:
sudo a2enmod rewrite
2. Restart Apache:
sudo service apache2 restart
我希望这将解决你的问题。