1

When I set $route['default_controller'] to 'blog', CI opens my controller without problems. When I want to access it via URL, CI returns a 404.

My controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends CI_Controller {

    public function index()
    {
        echo 'Hello World!';
    }
}

Saved at

application/controllers/Blog.php

Some other config things:

$route['default_controller'] = 'blog';
$route['404_override'] = '';
$config['base_url'] = '';

URL I try to use:

http://localhost:63342/project/public_html/blog/

.htaccess to hide index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

How can I fix this issue? I tried a lot of solutions from similar questions without success

6
  • Remove that slash in front of the index.php in your RewriteRule ... it's redirecting to your webroot. Commented Feb 6, 2016 at 14:58
  • @Narf Same result as before :/ Commented Feb 6, 2016 at 14:59
  • Yes, I suspected that alone wouldn't solve your problem, which is why I only left it as a comment ... But that surely is a part of the issue. Either way, it's nothing to do with CodeIgniter; you only need to tackle .htaccess and/or your Apache configuration. Commented Feb 6, 2016 at 15:03
  • Alright. I tried it without .htaccess too by using localhost:63342/project/public_html/index.php/blog which also gave me a 404 Commented Feb 6, 2016 at 15:09
  • try to add die("I am here"); in your index function and check. Commented Feb 6, 2016 at 15:28

1 Answer 1

1

If your project is in project folder in main directory of the local server, change your address to:

http://localhost:63342/project/blog

You configured that page as your default controller, so it should work even by:

http://localhost:63342/project
Sign up to request clarification or add additional context in comments.

2 Comments

My index.php lies in project/public_html, so the address is correct. As mentioned in my question [When I set $route['default_controller'] to 'blog', CI opens my controller without problems.] it work's when I open localhost:63342/project/public_html, but not on direct URL call
Your project should be in the main folder(root) of the website not public_html. If you using xampp as your local web server your project(which contains files like application index and htaccess) should be in: xampp/htdocs/project/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.