• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
404 error on simple controller

#1
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.
Reply

#2
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.
Reply

#3
(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
Reply

#4
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.
Reply

#5
(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
Reply

#6
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.
Reply

#7
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.
Reply

#8
(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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.