我是一个新手在PHP,我正在设置一个简单的路由使用AltoRouter。下面是我的index.php和.htaccess文件,它们位于路由文件夹中,即/var/www/html/我使用Apache2为网页提供服务。
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]问题:当我访问localhost时,'home.php‘得到服务,但当我访问'localhost/login’或'localhost/signup‘时,我得到404错误。
发布于 2016-08-31 05:15:00
我希望你能访问localhost/login.php .try it。
发布于 2016-08-31 05:44:03
更改此代码
 $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'; });以下是……
$router->map('GET', '/views', '/views/home.php','home');
$router->map('GET', '/views/login', '/views/login.php','login');
$router->map('GET', '/views/signup', '/views/signup.php','signup');发布于 2016-10-31 18:36:15
看起来你的.htaccess文件被忽略了,这不是由AltoRouter或PHP引起的。
根据您的操作系统,您应该搜索如何在系统上激活.htaccess文件。
https://stackoverflow.com/questions/39236995
复制相似问题