Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is link / href with just parameters (starting with question mark) valid?

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).

like image 972
johndodo Avatar asked Oct 24 '11 06:10

johndodo


People also ask

Are question marks allowed in URLs?

In a URL, the query starts with a question mark - the question mark is used as a separator, and is not part of the query string. If you also include a question mark in the query string, this would be treated as a literal question mark (i.e. it has no significance beyond that of a regular character).

What is the question mark in a URL called?

The question mark ("?", ASCII 3F hex) is used to delimit the boundary between the URI of a queryable object, and a set of words used to express a query on that object. When this form is used, the combined URI stands for the object which results from the query being applied to the original object.

Which tag includes a href parameter?

Definition and Usage. The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink.

Is href attribute mandatory?

The tag is fine to use without an href attribute. Contrary to many of the answers here, there are actually standard reasons for creating an anchor when there is no href. Semantically, "a" means an anchor or a link. If you use it for anything following that meaning, then you are fine.


1 Answers

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.

like image 164
Kobi Avatar answered Oct 11 '22 00:10

Kobi