我遇到了麻烦,不知道如何解决这个问题。
我有一个网站 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/