仅带参数(以问号开头)的链接/href 是否有效? [英] is link / href with just parameters (starting with question mark) valid?

查看:27
本文介绍了仅带参数(以问号开头)的链接/href 是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个链接有效吗?

<a href="?lang=en">eng</a>

我知道浏览器会按预期处理它,并且我知道 空链接就可以了 也是 - 但可以只指定参数吗?

I know the browsers treat it as expected and I know the empty link would be ok too - but is it ok to specify just the parameters?

我很好奇,因为问号 ("?") 只是大多数 HTTP 服务器 (AFAIK) 的约定,尽管我承认这是一个普遍的约定.

I am curious because question mark ("?") is only a convention by most HTTP servers (AFAIK), though I admit it is a prevailing one.

所以,回顾一下:

  1. 所有浏览器都会正确解释吗?

  1. will all browsers interpret this correctly?

这是在 RFC 中吗?

is this in RFC?

我会不会在使用它时遇到一些麻烦?

can I expect some trouble using this?

更新:点击时的预期操作是重定向到同一页面,但使用不同的 GET 参数(上例中的lang=en").

UPDATE: the intended action on click is to redirect to the same page, but with different GET parameters ("lang=en" in above example).

推荐答案

是的.
您可以在 RFC 1808 - 相对统一资源定位符中找到它:

在具有明确定义的基本 URL 的对象中
基址:
相对 URL 将按如下方式解析:

Within an object with a well-defined base URL of
Base: <URL:http://a/b/c/d;p?q#f>
the relative URLs would be resolved as follows:

?y =

RFC 3986 - 统一资源标识符 (URI):通用语法 重申相同, 并添加了更多细节,包括语法:

RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax restates the same, and adds more details, including the grammar:

relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

relative-part = "//" authority path-abempty
             / path-absolute
             / path-noscheme
             / path-empty     #; zero characters

现在,并不是说所有浏览器都按照标准来实现它,但看起来这应该是安全的.

Now, that is not to say all browsers implement it according to the standard, but it looks like this should be safe.

这篇关于仅带参数(以问号开头)的链接/href 是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆