CodeIgniter Forums

Full Version: 404 error on simple controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
(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
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...wordpress/

DocumentRoot = Path to your public folder.
(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...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
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.
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.
(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.