I am a noobie in PHP, I am setting up a simple Routing using AltoRouter. Below is my index.php and .htaccess file which are at the route folder i.e, /var/www/html/ I am using Apache2 for serving the web pages.
index.php
<?php
require 'vendor/AltoRouter.php';
$router = new AltoRouter();
// map homepage
$router->map('GET', '/', function () {
require __DIR__ . '/views/home.php';
});
$router->map('GET|POST', '/login', function () {
require __DIR__ . '/views/login.php';
});
$router->map('GET', '/signup', function () {
require __DIR__ . '/views/signup.php';
});
$match = $router->match();
// call closure or throw 404 status
if ($match && is_callable($match['target'])) {
call_user_func_array($match['target'], $match['params']);
} else {
// no route was matched
header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
?>
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Problem: When I visit localhost, the 'home.php' get served, but when I visit 'localhost/login' or 'localhost/signup', I get 404 error.