2016-08-23 119 views
1

您好我目前正在使用codeigniter和im在linux(ubuntu 14.04)中的设置有问题的项目,这个项目是在Windows机器上设置,是现在正在Linux机器上转移。Codeigniter没有得到除索引外的其他控制器

的问题是,当我去到这是http://localhost/它关系到我的索引网站的默认页面(这是正确workign),但是当我去到我的控制器的其它功能它总是给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错误。

在此先感谢。

回答

0

您是否已经尝试

http://localhost/index.php/lin/validate_credentials

对不起,我不太确定这是第一次,我会改正。

但是,如果它仍然无法正常工作。有可能是你的.htaccess出错了.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> 

对不起,如果我不能eplxain此行,行,但我总是把这个笨和完美的作品,刚刚变化RewriteBase,你可以在互联网上搜索,或者在这里搜索stackoverflow。

+0

第二个工作,但我想知道为什么我需要index.php?以及如何消除它,谢谢 –

+0

好吧,我会编辑我的答案,如果它会以某种方式帮助你,请给我一个upvote或复选标记谢谢。 @JohnGeliberte –

+0

而且,为了增加,默认情况下,index.php总是由codeigniter调用,这就是为什么你需要使用它。我很抱歉,我刚刚看到了@Manyank Pandey的回答,我忘了你现在使用的是Linux,我希望我仍然能够帮助你,因为我更喜欢windows用户。 –

0

这个问题是因为你的机器上没有启用mod_rewrite。试试这个:

1. Enable mod_rewrite by: 
sudo a2enmod rewrite 

2. Restart Apache: 
sudo service apache2 restart 

我希望这能解决你的问题。

+0

这仍然是一样的。它找不到404。 –

相关问题