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

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

问题描述

此链接是否有效?

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

我知道浏览器会按照预期处理它,并且我知道空链接也没关系 - 但可以指定参数吗?



我很好奇,因为问号(?)只是大多数HTTP服务器(AFAIK)的一个约定,尽管我承认它是盛行的。



<所以,回顾一下:


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


  2. 是RFC中的内容吗?


  3. 我可以预料到使用它会遇到一些麻烦吗?

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

解决方案

是的,它是。

您可以在RFC 1808 - 相对统一资源定位器



在具有明确定义的基本URL的对象中 -
Base:< URL:http:// a / b / c / d ; p?q#f>

相对URL将按以下方式解析:

5.1。正常示例



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


  relative-ref = relative-part [?查询] [#片段] 

relative-part =//权限path-abempty
/ path-absolute
/ path-noscheme
/ path -empty#;零字符

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


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.

So, to recap:

  1. will all browsers interpret this correctly?

  2. is this in 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).

解决方案

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

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:

5.1. Normal Examples

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

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天全站免登陆