CodeIgniter Forums
404 error on simple controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: 404 error on simple controller (/thread-77187.html)



404 error on simple controller - newcicoder - 07-30-2020

Hi.

I previously used CI 3 and i am new to CI 4.

My URL is accessible in :
Code:
http://localhost/my_git/ci4/public/

I have a simple controller like this
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Cron extends BaseController
{
    public function 
test() {
        
var_dump($this->request->uri->getSegment(3));
    }


I have adjusted my app/Config/App.php :
PHP Code:
public $baseURL 'http://localhost/my_git/ci4/public/'




My problem is :
if i open 
Code:
http://localhost/my_git/ci4/public/index.php/Cron/test/

I am redirected to
Code:
http://localhost/index.php/Cron/test


But if i open
Code:
http://localhost/my_git/ci4/public/index.php/Cron/test/abcdefg

It works correctly to the controller.

I have not modified routes.

Is there anything i should check?

Thank you.


RE: 404 error on simple controller - jreklund - 08-01-2020

I would just set up a proper virtual host, don't develop your application within the public folder. It won't be hosted that way.


RE: 404 error on simple controller - newcicoder - 08-01-2020

(08-01-2020, 06:27 AM)jreklund Wrote: I would just set up a proper virtual host, don't develop your application within the public folder. It won't be hosted that way.
I use localhost (xampp), and i don't put any additional php files on "public" folder. My controller, model, and view is on "app" folder, if that what you meant  Huh


RE: 404 error on simple controller - jreklund - 08-01-2020

I mean you should not access your application by using the "public" folder in your url. You need a real domain.
https://www.cloudways.com/blog/configure-virtual-host-on-windows-10-for-wordpress/

DocumentRoot = Path to your public folder.


RE: 404 error on simple controller - newcicoder - 08-01-2020

(08-01-2020, 06:57 AM)jreklund Wrote: I mean you should not access your application by using the "public" folder in your url. You need a real domain.
https://www.cloudways.com/blog/configure-virtual-host-on-windows-10-for-wordpress/

DocumentRoot = Path to your public folder.
Ok thank you for the suggestion.

Regarding error that i had, what codeigniter 4 setting that i should check?

Thank you


RE: 404 error on simple controller - jreklund - 08-01-2020

No idea, it could actually be a routing error in Apache. So it's a waste of time debugging a development environment that dosen't mirror a real world deployment.


RE: 404 error on simple controller - paulbalandan - 08-01-2020

Just to add. Don't end your URL with a trailing slash. It will be redirected by htaccess. Trailing slashes matter when not on the base URL.


RE: 404 error on simple controller - newcicoder - 08-01-2020

(08-01-2020, 08:40 AM)jreklund Wrote: No idea, it could actually be a routing error in Apache. So it's a waste of time debugging a development environment that dosen't mirror a real world deployment.
Thank you for the help

(08-01-2020, 09:47 AM)paulbalandan Wrote: Just to add. Don't end your URL with a trailing slash. It will be redirected by htaccess. Trailing slashes matter when not on the base URL.
Thank's i think that is correct ! When i don't end URL with trailing slash, it works.

Thanks for the help.