在地址栏中输入时index.php,它仍然不会重定向到indexwithout .php。试过在线测试 - 一切正常。错误在哪里?
$pattern = "/\.(php|html|asp|aspx|phtml|shtml)/i";
if(preg_match($pattern, $_SERVER['REQUEST_URI'])){
$currentPage = $_SERVER['REQUEST_URI'];
$shortCut = preg_replace($pattern, "", $shortCut);
header("Location:".$shortCut);
}
您正在函数
preg_replace()中使用未初始化的变量shortCut。排队$shortCut = preg_replace($pattern, "", $shortCut);你可能是说
$shortCut = preg_replace($pattern, "", $currentPage);