Welcome Guest, Not a member yet? Register   Sign In
File not found on my online server
#1

Hi, I've been trying to solve my problem all day but I haven't been able to solve it. Locally, my site works fine when I browse it. But on my online server, when I try to access the mywebsite.com/test page it gives me this error: File not found.

Routes.php

PHP Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/''Home::index');
$routes->get('test''Home::mytest'); 

Home.php

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function 
index(): string
    
{
        return 
view('welcome_message');
    }

    public function 
mytest()
    {
        echo 
"test...";
    }



All my files (app, public, tests, vendor, writable, etc.) are in the root of my server in the ‘www’ folder.

Thank you in advance for your help.
Reply
#2

Do you use nginx?
It seems your have something wrong with your web server configuration.
Reply
#3

I use a shared server from OVH.
Reply
#4

(This post was last modified: 05-10-2024, 05:17 PM by kenjis.)

See https://codeigniter4.github.io/CodeIgnit...g-services

But if your hosting service provides nginx, the user guide may not help you.
Reply
#5

(This post was last modified: 05-10-2024, 06:04 PM by Kobbs.)

I did as explained in this guide (first (and best) solution), I have a folder at the root of my server under the name www, which contains all the project files. And I've changed the root folder in the server settings so that it points directly to the public folder. I can try the other solutions suggested, but I don't understand why the first solution doesn't work.

I've just tried the other two solutions (with two directories, and using .htaccess) and the site still works, but the epas37.com/test route still doesn't work.
Reply
#6

You may need to change app/Config/App.php
PHP Code:
    /**
    * --------------------------------------------------------------------------
    * URI PROTOCOL
    * --------------------------------------------------------------------------
    *
    * This item determines which server global should be used to retrieve the
    * URI string. The default setting of 'REQUEST_URI' works for most servers.
    * If your links do not seem to work, try one of the other delicious flavors:
    *
    *  'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
    * 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
    *    'PATH_INFO': Uses $_SERVER['PATH_INFO']
    *
    * WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
    */
    public string $uriProtocol 'REQUEST_URI'


Also your server maybe case sensitive so you would need to use all lower case file names.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

The default value was already REQUEST_URI. I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest), the site is still operational but still returns the ‘File not found’ error when I try to access the epas37.com/test route.
Reply
#8

What is your web server software?
Reply
#9

(05-10-2024, 11:57 PM)Kobbs Wrote: I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest),

The change is wrong. You should not do like that.
You must name the file in the exact same case as the class name.
Because filenames in most servers are case sensitive.

E.g.,
1. if the classname is Home, then the file name must be Home.php
2. if the classname is home, then the file name must be home.php.
Reply
#10

(This post was last modified: 05-11-2024, 01:49 AM by Kobbs.)

(05-11-2024, 01:11 AM)kenjis Wrote:
(05-10-2024, 11:57 PM)Kobbs Wrote: I also tried as advised to leave my file names in lower case (Home.php -> home.php) and by modifying my Routes.php file (Home::mytest -> home::mytest),

The change is wrong. You should not do like that.
You must name the file in the exact same case as the class name.
Because filenames in most servers are case sensitive.

E.g.,
1. if the classname is Home, then the file name must be Home.php
2. if the classname is home, then the file name must be home.php.

Basically, my Home.php file contains the Home class (in upper case). When I modified it, I forgot to change the case, but unfortunately the problem remains the same.
If you want, I can put my project on github?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB