php - 此页面不工作 localhost 当前无法处理此请求。HTTP 错误 500
问题描述
当我尝试访问本地服务器上的网站管理面板时发生此错误这是我的管理面板 index.php 的代码
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$http_header = 'http://';
if (!empty($_SERVER['HTTPS'])) {
$http_header = 'https://';
}
$this_url = $http_header . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$this_url = str_replace('admin-panel', 'admin-cp', $this_url);
header("Location: $this_url");
exit();
?>
You can access the admin panel, from <a href="<?php echo $this_url ?>"><?php echo $this_url ?></a>
解决方案
admin-panel
在重定向之前尝试在 URL 中测试,如下所示:
if (strpos($this_url, 'admin-panel') !== false)
{
$this_url = str_replace('admin-panel', 'admin-cp', $this_url);
header("Location: $this_url");
exit();
}
如果str_replace('admin-panel', 'admin-cp', $this_url)
失败,则$this_url
保持不变。如果header
重定向到同一页面,您将收到诸如“无法处理请求 500 清除您的 cookie”之类的错误,或类似内容。