我正在嘗試設置一個小的路由系統,但是當我將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