Welcome Guest, Not a member yet? Register   Sign In
why routing not work
#1
Sad 
(This post was last modified: 01-08-2022, 07:02 PM by yoshi.)

hi there.
current theme is school.

PHP Code:
/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Home::index');
$routes->get('school''School::index'); 

(Picture1: I can't paste a image.)
`http://localhost:8080/school/`
not works.

but, for example ... change to `schoolx`

PHP Code:
/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Home::index');
$routes->get('schoolx''School::index'); 

(Picture2: I can't paste a image.)
`http://localhost:8080/schoolx/`
it works.

why routing not work??

infomation:
controller name is `School.php`
Reply
#2

What do you mean by not works?
Reply
#3

(This post was last modified: 01-09-2022, 04:37 AM by yoshi.)

(01-09-2022, 03:01 AM)kenjis Wrote: What do you mean by not works?

thank you  kenjis.
here, following  picture for error.
https://drive.google.com/file/d/1Tl92IK_...sp=sharing

Quote:[Sun Jan  9 20:10:28 2022] PHP 8.1.1 Development Server (http://localhost:8080) started
 :
[Sun Jan  9 20:11:16 2022] [::1]:51655 [404]: GET /school/ - No such file or directory

Why can't I paste images on this bulletin board?
Reply
#4

Do you have a school directory in public?
Reply
#5

(This post was last modified: 01-09-2022, 06:14 PM by yoshi.)

(01-09-2022, 09:20 AM)iRedds Wrote: Do you have a school directory in public?

iRedds, thank you for your reply.
Yes, there is a "school" directory.

Look at the next image.
https://drive.google.com/file/d/19Jxf0AP...sp=sharing
Reply
#6

Well, actually this is the problem.
First, the web server looks for paths in the DOCUMENT_ROOT (public directory) and if it doesn’t find it, then it passes control to php.

If you have a /public/school directory, then when you go to the address http://domain/school, the web server will try to read it.
So in your case, I would recommend changing the paths.
/public/assets/school
/public/assets/home
Reply
#7

(01-09-2022, 07:03 PM)iRedds Wrote: Well, actually this is the problem.
First, the web server looks for paths in the DOCUMENT_ROOT (public directory) and if it doesn’t find it, then it passes control to php.

If you have a /public/school directory, then when you go to the address http://domain/school, the web server will try to read it.
So in your case, I would recommend changing the paths.
/public/assets/school
/public/assets/home

Thank you iRedds. I solved it by creating the 'assets' folder.
Is it "codeigniter" to study this basic mechanism? Or is it "php"?

I want to know why such a routing accident happened
Reply
#8

The web server first of all looks for the directory or file specified in the URL.
By default, if a file or directory is not found, the server generates a 404 error.
For software routing to work, instructions are prescribed to the web server to redirect the processing of requests to the front controller in the absence of a file or directory.

Absolutely all frameworks work on this principle.
Reply
#9

(01-09-2022, 10:54 PM)iRedds Wrote: The web server first of all looks for the directory or file specified in the URL.
By default, if a file or directory is not found, the server generates a 404 error.
For software routing to work, instructions are prescribed to the web server to redirect the processing of requests to the front controller in the absence of a file or directory.

Absolutely all frameworks work on this principle.

thanks, I voted for you.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB