0

我需要的:

example.com/webpage/应该重定向到example.com/webpage

我在用:

$path = $_SERVER['REQUEST_URI'];
if(substr($path, -1) == '/')
{
    $path=rtrim( $path, '/\\' );
    header("Location: $path");
}

问题:

当有人请求主页时(带或不带斜杠),值$path变为'/'并导致循环。谁能给我一个更好的解决方案?

4

1 回答 1

-1

尝试

$path = $_SERVER['REQUEST_URI'];
$path = preg_replace('#/\s*$#', '', $path);
header("Location: $path");
于 2015-05-19T14:45:22.583 回答