php服务器request_uri忽略了URL最后一次斜线之后

发布于 2025-02-13 03:46:27 字数 667 浏览 0 评论 0原文

我正在尝试使用PHP获取当前页面URL,并且某种程度上无法正常工作。这是我现在正在使用的代码,

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
     $url = "https://";   
else  
     $url = "http://";   
$url.= $_SERVER['HTTP_HOST'];   
$url.= $_SERVER['REQUEST_URI'];    
  
echo $url;  

我将通过一个URL,例如https://example.com/a即使在URL结束时使用/a

https://example.com

不是

https://example.com/a

当URL在上一个斜线之后包含多个字符时,它正在与正确的URL相呼应,例如https://example.com/aa

您可以请让我知道为什么会发生这种情况以及如何解决这个问题?

I am trying to get current page URL using PHP and somehow it is not working properly. Here is the code that I am using

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
     $url = "https://";   
else  
     $url = "http://";   
$url.= $_SERVER['HTTP_HOST'];   
$url.= $_SERVER['REQUEST_URI'];    
  
echo $url;  

Now I pass a URL like https://example.com/a even with /a at the end of URL I am still getting

https://example.com

and NOT

https://example.com/a

It is echoing correct URL when URL contains more than one characters after last slash like https://example.com/aa

Can you please let me know why this is happening and how I can fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文