我正在尝试设置一个小的路由系统,但是当我将public/index.php重写为public/my $ _SERVER ['PATH_INFO]变量失败得到任何输入。
它正常工作,而不当我访问.htaccess文件:
公共/ index.php文件/你好
我得到:
欢迎您!这是主页。
但是,当我重写删除index.php,只有离开公众/我死在水中。
有没有人知道这个问题的解决方法或有人可以给我一个解释吗?基于这样落后的脚本
<?php
// First, let's define our list of routes.
// We could put this in a different file and include it in order to separate
// logic and configuration.
$routes = array(
'/' => 'Welcome! This is the main page.',
'/hello' => 'Hello, World!',
'/users' => 'Users!'
);
// This is our router.
function router($routes)
{
// Iterate through a given list of routes.
foreach ($routes as $path => $content) {
if ($path == $_SERVER['PATH_INFO']) {
// If the path matches, display its contents and stop the router.
echo $content;
return;
}
}
// This can only be reached if none of the routes matched the path.
echo 'Sorry! Page not found';
}
// Execute the router with our list of routes.
router($routes);
?>
我的.htaccess文件的URL数据呼应内容
简单的路由脚本
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule^/%1 [R=301,L]
更新#1
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
你可以检查你的* AcceptPathInfo *配置吗? – Gumbo
在您的RewriteCond中,您只是__ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _部件,然后您使用该部分重写为 - 因此_you_放弃原始请求URI中的index.php后面的任何内容...顺便说一句,我真的不明白'($ | \ | \?)'应该达到什么样的模式,请注意解释一下吗?) – CBroe
我不确定PATH_INFO甚至可以在这种情况下工作,因为这个值是任何在可能与_physically_存在的文件匹配的部分之后出现的路径 - 但是正是这个物理存在的文件在这里尝试取出来...... – CBroe