Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use an at symbol (@) inside URLs?

Is it safe to use an @ symbol as part of a user? For example, a possible URL would be http://example.com/@dave.

The idea is that, nowadays, users are commonly called "@user", so why not make the user page "@username"?

like image 985
Geoff Avatar asked Oct 22 '13 04:10

Geoff


People also ask

What symbols are not allowed in URL?

These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

Can an ampersand be used in a URL?

No. Unfortunately you can't use ampersands (&) as part of your domain name. Characters that you can use in your domain name include letters, numbers and hyphens.


1 Answers

Percent-encoded …

You can use the @ character in HTTP URI paths if you percent-encode it as %40.

Many browsers would display it still as @, but e.g. when you copy-and-paste the URI into a text document, it will be %40.

… but also directly

Instead of percent-encoding it, you may use @ directly in the HTTP URI path.

See the syntax for the path of an URI. Various unrelated clauses aside, the path may consist of characters in the segment, segment-nz, or segment-nz-nc set. segment and segment-nz consist of characters from the pchar set, which is defined as:

pchar = unreserved / pct-encoded / sub-delims / ":" / "@" 

As you can see, the @ is listed explicitly.

The segment-nz-nc set also lists the @ character explicitly:

segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) 

So, a HTTP URI like this is totally valid:

http://example.com/@dave 

Example

Here is an example Wikipedia page:

  • link
  • copy-and-paste: http://en.wikipedia.org/wiki/%22@%22_%28album%29

As you can see, the ", (, and ) characters are percent-encoded, but the @ and the _ is used directly.

like image 176
unor Avatar answered Oct 03 '22 19:10

unor