PHP - 将页面重定向到没有协议(protocol)的 URL?

标签 php url-redirection http-redirect

我遇到了麻烦,不知道如何解决这个问题。

我有一个网站 www.example.com .它在移动浏览器上打开,我必须重定向到 something://一个 Action 触发重定向后。

无论我多么努力,我都无法重定向到 something:// ,当我这样做时:

<?php header('Location: something://'); ?>我得到的是:http://www.example.com/something:// .

我一直在尝试使用 JS(location.replace.href、location.replace 等),但也不走运。

如何强制 URL 以我想要的方式更改?

最佳答案

RFC 2616说:

Location = "Location" ":" absoluteURI

RFC 2396 中指定了 absoluteURI .

  absoluteURI   = scheme ":" ( hier_part | opaque_part )
  relativeURI   = ( net_path | abs_path | rel_path ) [ "?" query ]

  hier_part     = ( net_path | abs_path ) [ "?" query ]
  opaque_part   = uric_no_slash *uric

  uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
                  "&" | "=" | "+" | "$" | ","

  net_path      = "//" authority [ abs_path ]
  abs_path      = "/"  path_segments

  authority     = server | reg_name

  reg_name      = 1*( unreserved | escaped | "$" | "," |
                      ";" | ":" | "@" | "&" | "=" | "+" )

  server        = [ [ userinfo "@" ] hostport ]
  userinfo      = *( unreserved | escaped |
                     ";" | ":" | "&" | "=" | "+" | "$" | "," )

  hostport      = host [ ":" port ]
  host          = hostname | IPv4address
  hostname      = *( domainlabel "." ) toplabel [ "." ]
  domainlabel   = alphanum | alphanum *( alphanum | "-" ) alphanum
  toplabel      = alpha | alpha *( alphanum | "-" ) alphanum
  IPv4address   = 1*digit "." 1*digit "." 1*digit "." 1*digit
  port          = *digit

据此,如果您使用的是 something:// 协议(protocol),则需要指定 authority 部分 - 斜杠不能是字符串的最后部分,例如something://example

但是,最终决定重定向位置的始终是客户端的浏览器,出于安全原因,它可能会拒绝重定向到非 HTTP(S) URL。

关于PHP - 将页面重定向到没有协议(protocol)的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34061743/

相关文章:

php - 简单的PHP MVC框架设计

php - 如何使用 PHP、HTML 等从多个页面中选择项目?

redirect - 301重定向是否会带来Google惩罚?

SharePoint SaveButton RedirectURL 属性不执行任何操作。为什么?

url - 浏览器如何使用查询字符串缓存 301 重定向

php - { } codeigniter 模型/ View 中的大括号

php - 使用php将mysql表合并到一个表中

.htaccess - 默认语言根级别

apache - 将 http 重定向到 https 排除特定 IP

Django 从一个页面重定向到另一个页面