转到 HTTPS 时 URL 末尾有双斜线?

发布于 2024-09-01 12:41:11 字数 942 浏览 5 评论 0原文

我的网站目前根据网站上收集的数据使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小…红帽 2024-09-08 12:41:11

dirname() 不适用于 PHP_SELF,因为它不一定是完整目录。

dirname("/enroll.php") 将正确返回一个空字符串,这又会导致双 //

你到底想做什么?

dirname() won't work on PHP_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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文