link / href只是参数(以问号开头)有效吗?

时间:2021-01-04 16:06:05

Is this link valid?

这个链接有效吗?

<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?

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

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

我很好奇,因为问号(“?”)只是大多数HTTP服务器(AFAIK)的惯例,尽管我承认它是一个普遍的。

So, to recap:

所以,回顾一下:

  1. will all browsers interpret this correctly?

    所有浏览器都能正确解读吗?

  2. is this in RFC?

    在RFC中是这样的吗?

  3. can I expect some trouble using this?

    我可以期待使用它有些麻烦吗?

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

更新:关于点击的预期操作是重定向到同一页面,但具有不同的GET参数(上例中为“lang = en”)。

2 个解决方案

#1


30  

Yes, it is.
You can find it in RFC 1808 - Relative Uniform Resource Locators:

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

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:

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

5.1. Normal Examples

?y = <URL:http://a/b/c/d;p?y>

?y = :http:>

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

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

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.

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

#2


0  

Yes - and it will hit the current url with parameters what you are passing.

是的 - 它将使用您传递的参数来点击当前网址。

It is very convenient to use in situations where you want to make sure you do not cross current page/form boundary and keep on hitting same ActionMethod or whatever is listening with different parameters.

在您希望确保不跨越当前页面/表单边界并继续使用相同的ActionMethod或任何正在使用不同参数进行侦听的情况下,使用它非常方便。

#1


30  

Yes, it is.
You can find it in RFC 1808 - Relative Uniform Resource Locators:

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

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:

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

5.1. Normal Examples

?y = <URL:http://a/b/c/d;p?y>

?y = :http:>

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

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

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.

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

#2


0  

Yes - and it will hit the current url with parameters what you are passing.

是的 - 它将使用您传递的参数来点击当前网址。

It is very convenient to use in situations where you want to make sure you do not cross current page/form boundary and keep on hitting same ActionMethod or whatever is listening with different parameters.

在您希望确保不跨越当前页面/表单边界并继续使用相同的ActionMethod或任何正在使用不同参数进行侦听的情况下,使用它非常方便。