转到 HTTPS 时 URL 末尾有双斜线?
我的网站目前根据网站上收集的数据使用 http 和 https 部分(表单数据使用 https)。
在我的索引页面上,我的顶部有 PHP 代码:
<?php
session_start();
ob_start();
if( $_SERVER['SERVER_PORT'] == 443) {
header('Location:http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']));
die();
}
?>
但是,该页面不会加载,并且出现 404 错误。同样,当我使用头代码访问具有 https 安全性的部分时:
<?php
session_start();
ob_start();
if( $_SERVER['SERVER_PORT'] == 80) {
header('Location:https://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.basename($_SERVER['PHP_SELF']));
die();
}
?>
该站点没有响应,并且由于某种原因在从 http 切换到 https 时会创建双斜杠。
示例: http://www.abc.com/,然后单击应路由到 enroll.php 的按钮显示 http://www.abc.com//enroll.php
为什么需要双斜杠,有人可以帮助解决 404 错误吗?
My site currently uses http and https sections based on the data being collected on the site (form data uses https).
On my index page, I have the PHP code at the top:
<?php
session_start();
ob_start();
if( $_SERVER['SERVER_PORT'] == 443) {
header('Location:http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']));
die();
}
?>
However, the page will not load and I get a 404 error. Similarly, when i visit the sections with https security using the head code:
<?php
session_start();
ob_start();
if( $_SERVER['SERVER_PORT'] == 80) {
header('Location:https://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.basename($_SERVER['PHP_SELF']));
die();
}
?>
The site does not respond AND for some reason creates a double slash when switching from http to https.
Example: http://www.abc.com/, then clicking button which should route to enroll.php shows http://www.abc.com//enroll.php
why the need for the double slash and can anybody help with the 404 errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dirname()
不适用于PHP_SELF
,因为它不一定是完整目录。dirname("/enroll.php")
将正确返回一个空字符串,这又会导致双//
。你到底想做什么?
dirname()
won't work onPHP_SELF
because that is not necessarily a full directory.dirname("/enroll.php")
will correctly return an empty string, which in turn leads to the double//
.What exactly are you trying to do?