Welcome Guest, Not a member yet? Register   Sign In
Following tutorial and getting a 404 when accessing controllers

I'm following the tutorial and got as far as the controllers section.  Accessing http://localhost/codeIgniter/index.php/blog works but accessing http://localhost/codeIgniter/index.php/blog/comments does not. It throws a 404 error.

I've got base_url set as so: $config['base_url'] = 'http://localhost/codeIgniter';

I've tried adding this to my .htaccess in the /www/codeIgniter directory (as well as a couple variations I found while googling):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Mod rewrite is installed.

I've got AllowOverride All in my httpd.conf file.

I also set the index_page as blank.

I've also just tried not rewriting anything.

I'm running on WAMP on Windows 7 with Apache 2.435, and have tried PHP 5.6 and 7.

Have been at this for a couple hours now, please help?


(This post was last modified: 01-08-2019, 10:49 AM by jreklund.)

Can you enable the debug log in application\config\config.php.
And you will find them in application\logs

Can you print screen the 404 message? So we can see if it's Codeigniter or your webbserver that gives you that message.

Try adding a trailing slash to the base_url string.

I have had what I think is the same problem when following the tutorial. The problem is that when the function site_url() is used to get the first part of a link, it does correctly get "localhost/index.php" and adding "/news/create" (for example) completes the link. And as stated in the initial question, following that link gets a 404 error.

I played around a bit, and found that while in the source, a the link will indeed show "localhost/index.php/news/create", but hovering over the link in the browser shows that the server (apache in my case) expects to go to  "localhost/index.php/localhost/index.php/news/create". And indeed the 404 page does say it can't find that page.

I haven't quite worked out if adjustments need to be made in the web server configs of codeigniter. If some one could give a hint that would be good.

Further info that maybe helpful. I got things going by not using the site_url function, instead giving an absolute reference. So for the example I give my href is "/index.php/news/create". Works every time.

My setup is straight out of the box, with

$config['base_url'] = 'localhost/';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';

Hopes this helps. And any suggestions about why things actually work for me wuld be greatly appreciated.

Some time you need to change:

From this:
PHP Code:
RewriteRule ^(.*)$ index.php/$[L

To this:
RewriteRule ^(.*)$ index.php?/$1 [L]
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB