需要PHP路由帮助

时间:2013-09-06 08:34:29

标签: php .htaccess routes

我的.htaccess文件是这样的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

我的index.php

echo '<pre>';
print_r(explode('/', $_SERVER['REQUEST_URI']));
echo '</pre>';

当我去example.com/test/one/two时,它会让我回来:

Array
(
    [0] => 
    [1] => test
    [2] => one
    [3] => two
)

为什么有0?

1 个答案:

答案 0 :(得分:1)

因为您的$_SERVER['REQUEST_URI']/test/one/two

要摆脱它,你可以从$_SERVER['REQUEST_URI']删除第一个斜杠:

substr($_SERVER['REQUEST_URI'], 1);