Hello everybody I am new with Routing systems in Php. Searching on the web I have found this short code for explain how routing should work but... I cannot understand in which way It routes my request to the desired page:
<?php
// Get the requested path with $_SERVER['REDIRECT_URL'],
// and require the page you want to display. I have '' and '/' for both url.com/ and url.com.
// REDIRECT_URL returns normal url e.g. /review,
// in the other hand REQUEST_URI returns including query string e.g. /review?page=4
$request = $_SERVER['REDIRECT_URL'];
switch ($request) {
case '/' :
require __DIR__ . '/views/index.php';
break;
case '' :
require __DIR__ . '/views/index.php';
break;
case '/about' :
require __DIR__ . '/views/about.php';
break;
default:
require __DIR__ . '/views/404.php';
break;
}
When I open it the first time it redirect me to index.php:
<h1>main</h1>
and the other page is about.php:
<h1>about</h1>
My question is: how can I switch to about.php using the routing system?
Because If I write inside the url localhost/simpleRouter/views/about.php it looks like I am bypassing the routing system.... so I cannot figure out how can I use it properly to switch between pages. Morover, the index.php page shows me MAIN and this is good, but i receive a the following:
Notice: Undefined index: REDIRECT_URL in D:\App\xAMPP\htdocs\studio\Php\SviluppareInPHP7\CAP7\simpleRouter\index.php on line 9
Thank you for answering my questions and helping me to improve my knowledge on this field.