CodeIgniter Forums
Following tutorial and getting a 404 when accessing controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forum-9.html)
+--- Thread: Following tutorial and getting a 404 when accessing controllers (/thread-72580.html)



Following tutorial and getting a 404 when accessing controllers - PopcornForest - 01-07-2019

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?

TIA


RE: Following tutorial and getting a 404 when accessing controllers - jreklund - 01-08-2019

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.


RE: Following tutorial and getting a 404 when accessing controllers - dave friend - 01-08-2019

Try adding a trailing slash to the base_url string.


RE: Following tutorial and getting a 404 when accessing controllers - chrisknew - 02-14-2019

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.


RE: Following tutorial and getting a 404 when accessing controllers - InsiteFX - 02-16-2019

Some time you need to change:

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

To this:
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]