0

I am new to Kohana. I am using the default route in Kohana 3.2 which is

Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
    'controller' => 'admin',
    'action'     => 'login',
));

My controller is as follows :

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin extends Controller{

public function __construct($request, $response) {
    parent::__construct($request, $response);
}

public function action_login(){
    $session = Session::instance();
    if($session->get('admin_id')){
        //Session is set / Logged in
        $this->request->redirect('users/list');
        exit();
    }

    if($_POST){
       $user = ORM::factory('admin');
       $post = Validation::factory($_POST)
               ->rule('username', 'not_empty')
               ->rule('password', 'not_empty');
        if(!$post->check()){
            Message::error($post->errors('admin'));
        }
        else{
            $objUserDetails = $user->checkCredentials($_POST);
            if($objUserDetails->id){
                //Valid username and password
                $session->set('admin_id', $objUserDetails->id);
                $this->request->redirect('users/list');
                exit();
            }
            else{
                Message::error("Invalid username or password");
                $this->request->redirect('admin/login');
                exit();
            }
        }
    }

    $this->response->body(new View(
                'login',
                array('title'=>'Administrator login')
            ));
}

public function action_logout(){
    $session = Session::instance();
    $session->delete('admin_id');
    $session->destroy();
    $this->request->redirect('admin/login');
}

}

My .htaccess is as follows :

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

When I type http://localhost it is working properly. But when I type http://localhost/admin/login or http://localhost/admin/logout it is showing a 404 error.

Please help.

hakre
  • 193,403
  • 52
  • 435
  • 836
ajaybc
  • 4,049
  • 7
  • 44
  • 57
  • 2
    Do you have your `.htaccess` turned on? Try to type something wrong like "foobar" there and check if for the request you get 500 error – zerkms May 15 '12 at 09:56
  • @zerkms I did as you told. Instead of 500 I am getting 404 error. That means mod_rewrite is disabled right ? – ajaybc May 15 '12 at 10:06
  • 2
    it means that the whole `.htaccess` is disabled. Find `AllowOverride` and set it as `All` in your `httpd.conf` – zerkms May 15 '12 at 10:07

1 Answers1

3

You have your .htaccess disabled, so you need to find AllowOverride and set it as All in your httpd.conf

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • 1
    Seems a lot of people are having this issue, but good to know this information has been added to the 3.3 docs: https://github.com/kohana/core/blob/3.3/develop/guide/kohana/tutorials/clean-urls.md#404-errors – badsyntax May 15 '12 at 10:32
  • 1
    `tutorials/clean-urls` page has this information for all 3.x versions – biakaveron May 15 '12 at 10:54
  • @biakaveron documentation about this specific issue was added recently: https://github.com/kohana/core/pull/203 – badsyntax May 15 '12 at 11:14